【问题标题】:How to get current time with milliseconds如何以毫秒为单位获取当前时间
【发布时间】:2014-07-03 16:35:13
【问题描述】:

我正在使用 TCL 8.6 版本并尝试使用 TCL“以毫秒获取当前时间”。

我愿意得到的输出如下:使用示例时间

11:06:52.123

【问题讨论】:

    标签: time tcl milliseconds


    【解决方案1】:
    set t [clock milliseconds]
    set timestamp [format "%s.%03d" \
                      [clock format [expr {$t / 1000}] -format %T] \
                      [expr {$t % 1000}] \
                  ]
    

    回过头来看,我会使用辅助 proc 来整理:

    proc divmod {numerator divisor} {
        list [expr {$numerator / $divisor}] [expr {$numerator % $divisor}]
    }
    
    lassign [divmod [clock milliseconds] 1000] sec milli
    set timestamp [format {%s.%03d} [clock format $sec -format %T] $milli]
    

    【讨论】:

    • 非常感谢格伦...!
    猜你喜欢
    • 2017-04-25
    • 1970-01-01
    • 2011-10-25
    • 2017-02-20
    • 1970-01-01
    • 2011-05-10
    • 2015-12-28
    相关资源
    最近更新 更多