Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCL Command 1

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
US
I have a question.
can TCL command read Time format?
for example,

set a 13:55
set b 02:15

set result $a + $b

puts $result will be 16:10

is it possible?
 
Not quite. You'd be best advised, I think, to use the clock function, with both its scan and format options:
Code:
set a 13:55
set b 02:15
set a1 [clock scan $a]
set b1 [clock scan $b]
#now both are in internal (POSIX) time
set r1 [expr {$a1+$b1}]
set result [clock format $r1 -format %k:%M]

Bob Rashkin
rrashkin@csc.com
 
Sorry that isn't quite right. Since they're both converted to dates it won't work that way. You have to convert the second time, 2:15, to seconds and add that to the first:
Code:
set a 13:55
set b 02:15
set a1 [clock scan $a]
set b1 [split $b :]
set b2 [expr {[lindex $b1 0]*3600 + [lindex $b1 1]*60 + $a1}]
#now the sum is internal (POSIX) time
set result [clock format $b2 -format %k:%M]

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top