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

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
US
hi, I have a Question about time.
how can I make the hour and minute be two digits??
for example,
5--> 05
can I use like this way??
if {$minFormat <10 } {
set minFormat "0$minFormat"
}
thank you in advance
 
Let's say you have a variable, hr, for the hours, and another one, mn, for the minutes. Then format "%02i:%02i" $hr $mn will format the time as hh:mm.

Bob Rashkin
rrashkin@csc.com
 
hi...thank you for your response

this is my code..and I tried, but I could not get two digits.

-----------

set minFormat [expr int(fmod($endTimeMin,60))]

set hourFormat [expr int($endTimeHour + 1)]

#format "%02i" $minFormat ---> this is only for the minute.

#this is what I have now..this works, but it does not look good...so....
if {$minFormat <10 } {
set minFormat "0$minFormat"
}

--------------------

Thank you in advance...
 
Well, it depends on what you want to do with it. For instance, if you just want to return the formatted value in the console, puts [format "%02i" $minFormat] will do it. If you want a persistent string that has the formatted characteristics, set minString [format "%02i" $minFormat] is what you want.

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

Part and Inventory Search

Sponsor

Back
Top