mlr --csv put ' $time1=sec2gmt( localtime2sec( ...

问题描述 投票:0回答:1
I found two similar expressions, both of which use

instead of to parse the local date and time string and convert it to seconds since the Epoch in UTC (GMT):Both UTC and

$ printf "time1\n2019-06-13 05:54 PM\n" | mlr --csv put '
  $time1=sec2gmt(
    localtime2sec(
      strftime(
        strptime($time1, "%Y-%m-%d %H:%M %p"),
        "%Y-%m-%d %H:%M:%S")));'
time1
2019-06-13T10:54:00Z

assume an argument of seconds since the Epoch in UTC.EDTFunction -04:00 assumes an input date and time string in UTC and ignores a time zone in the input string:

$ date --date='2019-06-13 05:54 PM' '+%Y-%m-%dT%H:%M:%S %Z'
2019-06-13T17:54:00 EDT
$ date --date='2019-06-13 05:54 PM' '+%Y-%m-%dT%H:%M:%S%z'
2019-06-13T17:54:00-0400
Function
csv utc gmt localtime miller
1个回答
1
投票

怎样才能 strptime_local()Miller 5.6.2strptime() 将本地日期和时间转换为

$ printf "time1\n2019-06-13 05:54 PM\n" | mlr --csv put '
  $time1=strftime(
    strptime_local($time1, "%Y-%m-%d %H:%M %p"),
    "%Y-%m-%dT%H:%M:%SZ");'
time1
2019-06-13T10:54:00Z
$ printf "time1\n2019-06-13 05:54 PM\n" | mlr --csv put '
  $time1=sec2gmt(strptime_local($time1, "%Y-%m-%d %H:%M %p"));'
time1
2019-06-13T10:54:00Z

使用一个比下面更简单的表达式?strftime()请注意,我所在的地方时区在六月是 sec2gmt()

:strptime()

$ printf "time1\n2019-06-13 05:54 PM\n" | mlr --csv put '
  $time1=strptime($time1, "%Y-%m-%d %H:%M %p");'
time1
1560405240.000000
$ printf "time1\n2019-06-13 05:54 PM EDT\n" | mlr --csv put '
  $time1=strptime($time1, "%Y-%m-%d %H:%M %p %Z");'
time1
1560405240.000000

strptime_local()Miller如何使用比下面更简单的表达式将本地日期和时间转换为UTC?$ printf "time1\n2019-06-13 05:54 PM\n"

© www.soinside.com 2019 - 2024. All rights reserved.