您将需要单独处理毫秒数据。此外,用于gensub()
格式化您的字符串信息。像这样运行:
awk -f script.awk
内容script.awk
:
BEGIN {
string = "2012-12-20T01:16:02.05"
groups = "^(....)-(..)-(..).(..):(..):(..).*"
format = "\\1 \\2 \\3 \\4 \\5 \\6"
datespec = gensub(groups, format, "", string)
timestamp = mktime(datespec)
newstring = strftime("%F-%H.%M.%S", timestamp)
sub(/.*\./,"",string)
printf "%s.%s0000\n", newstring, string
}
结果:
2012-12-20-01.16.02.050000
编辑:
BEGIN {
string = "2011-01-10T14:45:13.815-05:00"
groups = "^(....)-(..)-(..).(..):(..):(..).*"
format = "\\1 \\2 \\3 \\4 \\5 \\6"
datespec = gensub(groups, format, "", string)
timestamp = mktime(datespec)
sub(/.*\./,"",string)
offset = substr(string,4)
split(offset,array,":")
seconds = (array[1] * 60 * 60) + (array[2] * 60)
newstring = strftime("%F-%H.%M.%S", timestamp - seconds, 1)
printf "%s.%s00\n", newstring, substr(string,0,3)
}
结果:
2011-01-10-09.45.13.81500