Oct 21, 2004 #1 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 ?
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 ?
Oct 21, 2004 1 #2 cptk Technical User Mar 18, 2003 305 US 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 Upvote 0 Downvote
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
Oct 21, 2004 #3 cptk Technical User Mar 18, 2003 305 US 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. Upvote 0 Downvote
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.