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!

Time Format 1

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
US
I am trying to convert integer to TimeFormat.

for example,

01:30 (1 hr 30 min)
60 (min)

set timeformat [split "01:30" :]
set minformat 60

set result [expr $timeformat + $minformat]

puts $result

but how to convert from 190 (min) to 02:30 ?

 
you can't just use set result [expr $timeformat + $minformat] the way it is. The variable "timeformat" is actualy a list "01 30".

You need to access each value in the list!

You can either use ...

foreach x $timeformat to access each value, but this would be cumbersome. Better to use the scan cmd.

>set timeformat [split "01:30" :]
>scan $timeformat "%d %d" hour min

then use the two variables accordingly
 
Not addressing your code logic-wise, but from purely a code perspective:

You can also access your $timeformat list like this using:

>[lindex $timeformat 0]
>[lindex $timeformat 1]

e.g.)
set result [expr [lindex $timeformat 0] + $minformat]


To answer "but how to convert from 190 (min) to 02:30", you can't ... you mean 150 or 03:10?

use "expr fmod(190,60)" to give you "10" and
use "expr int(190,60)" to give you "3"; then concatemate them with a ":" betw. them.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top