I need to convert time in seconds to HH:MM:SS.mm
format. The seconds input is being read from an embedded device, and it is a double
of the format seconds.millseconds
. I tried the following conversion code but it fails:
set cpu_time [function_that_fetches_the_time]
puts "[clock format $cpu_time -format {%H:%M:%S}]"
This fails with the error
expected integer but got "98.92"
thrown from
"ParseFormatArgs {*}$args"
(procedure "::tcl::clock::format" line 6)
I could convert the double to an integer and the above would work, but it'd be nice to have the milliseconds part in the output display too.
Also, what is the clock format specifier for milliseconds?
EDIT:
Seems only converting the double
to an int
doesn't work either. I tried
puts "[clock format [expr int($cpu_time)] -format {%H:%M:%S}]"
and it results in some strange time. For instance, when the embedded device returns 3.53
(and I cast it to a 3
) the time printed out is 17:00:03
.