Reputation: 1
I have three questions, all of them closely related to each other. The most important one is the first one.
First: I am trying to display the current time in the format hours:minutes:seconds, so
set systemTime [clock seconds]
puts "The time is: [clock format $systemTime -format %H:%M:%S]"
But the above clock should be permanently updated, that is, the seconds-part of the clock should be running all the time.
Second: In the next step I would like to display milliseconds and they should be updated as well.
Third: I would like to execute a procedure at a certain point of time. More precisely: At a certain time, say 16:20 (the format here is hours:minutes), tcl musst execute a procedure, say proc SumUpInt, which I defined. It may be possible that I want to consider seconds and milliseconds as well when executing the proc.
I do not know how to do this. I have found many similar questions on some web sites, also on stack overflow, but I was not able to adapt some of these solutions to my problem.
Any help is welcome!
Thank you in advance.
Upvotes: 0
Views: 414
Reputation: 246877
There doesn't seem to be an output directive in clock format
for milliseconds, so perhaps:
proc timestamp {} {
set t [clock milliseconds]
set systemTime [expr {int($t / 1000)}]
set milliSeconds [expr {$t % 1000}]
return [format "%s.%03d" [clock format $systemTime -format %T] $milliSeconds]
}
timestamp ;# => 14:41:13.032
You can turn this "realtime" with
proc run_timestamp {} {
puts -nonewline "\r[timestamp] "
flush stdout
after 100 run_timestamp
}
run_timestamp
vwait forever
But the vwait
means this will block the Tcl interpreter. I don't have any thoughts right now about how to integrate this into your terminal.
Upvotes: 0