Nitin Sagar
Nitin Sagar

Reputation: 31

How to get current time with milliseconds

I am using TCL 8.6 version and trying to "get current time with milliseconds" using TCL.

Output I am willing to get is as below: using example time

11:06:52.123

Upvotes: 2

Views: 11075

Answers (1)

glenn jackman
glenn jackman

Reputation: 247210

set t [clock milliseconds]
set timestamp [format "%s.%03d" \
                  [clock format [expr {$t / 1000}] -format %T] \
                  [expr {$t % 1000}] \
              ]

Looking back at this, I'd use a helper proc to tidy things up:

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]

Upvotes: 13

Related Questions