从约会开始以毫秒为单位获得时间

时间:2013-03-17 18:25:13

标签: tcl

是否可以使用一串日期,例如2013-02-26 10:45:54,082并从“epoch”获取以毫秒为单位的时间?或类似的东西?

我知道clock scan以秒为单位返回时间。 另外clock scan会返回此特定格式的错误。

我无法找到我想要的东西,我想在开始创建之前确保它不存在......

由于

1 个答案:

答案 0 :(得分:2)

Tcl不支持毫秒级偏移(因为它在实践中是一种非常罕见的格式),但您可以解决这个问题:

set str "2013-02-26 10:45:54,082"
regexp {^([^\.,]*)[\.,](\d+)$} $str -> datepart millipart; # split on the last occurrence of , or . 
set timestamp [clock scan $datepart -format "%Y-%m-%d %H:%M:%S" -gmt 1]
scan $millipart "%d" millis
set millistamp [expr {$timestamp*1000 + $millis}]

(你不提供时区信息,所以我假设它是UTC,即“GMT”。我也允许使用.代替,作为毫秒分隔符,你得到的取决于首先创建时间字符串的语言环境。)