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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting mins to hours and mins

Status
Not open for further replies.

dcomit

Technical User
Jun 20, 2001
115
GB
Tcl 8.4 on Solaris 10

I’m trying to convert minutes to hours and minutes.
Code:
set x [lindex $xlateInVals 0]
set x [string trimleft $x 0]
set x [expr $x * 60]
set hhmm [clock format $x -format "%H%M"]
puts "Time Out >$hhmm<"
set xlateOutVals $hhmm
If xlateInVals is 0141 the result I’m getting is 0321, but it should be 0221. I’m obviously doing something wrong but I can’t work out what.

Thanks,
Dave
 
You need to set the GMT flag, otherwise the clock interpreter will try to be "helpful":
Code:
% clock format $x -format "%H%M" -gmt 1
0221

_________________
Bob Rashkin
 
It doesn't work for me.
Code:
tcl>set x 0141
0141
tcl>set hhmm [clock format $x -format "%H%M" -gmt 1]
0001
 
You still need to pass a number of seconds into the clock format.

_________________
Bob Rashkin
 
You're absolutely right - thanks.
Code:
tcl>set x 141
141
tcl>set hhmm [clock format [expr $x*60] -format "%H%M" -gmt 1]
0221
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top