Time#now

Hey guys, i have something like this

T = Time.now
TIME = "[#{$T.hour}:#{$T.min}:#{$T.sec}]"

The time format works perfectly for me unless either the minutes, hours
or seconds are 1 digit, it doesnt add a 0 in front of them, i would like
to keep them 2 digits, anyone have any idea?

3:45:8

I want, 03:45:08

Tia

···

--
Posted via http://www.ruby-forum.com/.

Lee Jarvis pisze:

Hey guys, i have something like this

T = Time.now
TIME = "[#{$T.hour}:#{$T.min}:#{$T.sec}]"

The time format works perfectly for me unless either the minutes, hours
or seconds are 1 digit, it doesnt add a 0 in front of them, i would like
to keep them 2 digits, anyone have any idea?

3:45:8

I want, 03:45:08

Tia

t = Time.now
puts "%02d:%02d:%02d" % [t.hour,t.min,t.sec]

lopex

Lee Jarvis pisze:

> I want, 03:45:08

t = Time.now
puts "%02d:%02d:%02d" % [t.hour,t.min,t.sec]

Google strftime - you'll probably hit PHP's version - then do
Time.now.strftime("%H:%M:%S"), with the appropriate codes in there.

···

--
Phlip

Perfect, thanks guys

···

--
Posted via http://www.ruby-forum.com/.

Don't google, ri. It has the full chart.

···

On Sep 12, 2007, at 16:25, Phlip wrote:

Lee Jarvis pisze:

I want, 03:45:08

t = Time.now
puts "%02d:%02d:%02d" % [t.hour,t.min,t.sec]

Google strftime

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars