可能是TCL错误的原因:
Tcl错误:无法转换日期时间字符串" Wed May 14 05:20:15 RET 2014"
执行clock scan $Date
% echo $tcl_version
8.4
% info patchlevel
8.4.19
很少有人建议升级到TCL 8.5,但想知道这个问题是否可以在8.4中解决。
答案 0 :(得分:1)
这是我认为Tcl 8.4让你跳过的箍:(在Tcl 8.3.3中测试)
% set dt "Wed May 14 05:20:15 RET 2014"
Wed May 14 05:20:15 RET 2014
% regsub RET $dt "" dt_alt
1
% set offset +4
+4
% set epoch [clock scan "$offset hours" -base [clock scan $dt_alt -gmt 1]]
1400026815
% clock format $epoch -gmt 1
Wed May 14 00:20:15 GMT 2014
其中
Tcl 8.5仍然无法解析那个确切的字符串:
% set dt "Wed May 14 05:20:15 RET 2014"
Wed May 14 05:20:15 RET 2014
% clock scan $dt
unable to convert date-time string "Wed May 14 05:20:15 RET 2014": syntax error (characters 19-22)
但
% set epoch [clock scan [string map {RET ""} $dt] -format {%a %b %d %T %Y} -timezone :Indian/Reunion]
1400030415
% clock format $epoch
Tue May 13 21:20:15 EDT 2014
% clock format $epoch -timezone :Indian/Reunion
Wed May 14 05:20:15 RET 2014
答案 1 :(得分:0)
你有语法问题。日期应为“Wed May 14 05:20:15”。 例如:
set Date "Wed May 14 05:20:15"
clock scan $Date
或者如果你有Date =“Wed May 14 05:20:15 RET 2014”那么:
clock scan "[lindex $Date 0] [lindex $Date 1] [lindex $Date 2] [lindex $Date 3]"