更新时间:2023-02-26 16:20:41
虽然我希望有一个简短的gnuplot 集成"解决方案,但我通过定义自己的公式提出了一个有点冗长"的解决方案.
That's a somewhat "lengthy" solution I have come up with by defining my own formula, although I was hoping for a short "gnuplot-integrated" solution.
代码:
### change 12h time format to 24h format
reset session
$Data12 <<EOD
12/31/19 8:12:01 AM
12/31/19 8:12:02 PM
12/31/19 12:00:03 am
12/31/19 12:00:04 pm
EOD
myTimeFmt12a = "%m/%d/%y"
myTimeFmt12b = "%H:%M:%S"
myTimeFmt24 = "%d.%m.%Y %H:%M:%S"
# change 12h am/pm format to 24h format
myTime12to24(t,p) = t+12*3600*(floor(t/3600)<12 && (p eq "PM" || p eq "pm") ?
1 : floor(t/3600)==12 && (p eq "AM" || p eq "am") ? -1 : 0)
set table $Data24
plot $Data12 u (strftime(myTimeFmt24,timecolumn(1,myTimeFmt12a) +
myTime12to24(timecolumn(2,myTimeFmt12b),strcol(3)))) w table
unset table
print $Data24
### end of code
结果:
31.12.2019 08:12:01
31.12.2019 20:12:02
31.12.2019 00:00:03
31.12.2019 12:00:04