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

Lee J. pisze:

I want, 03:45:08

Tia

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

lopex

Lee J. 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.

Perfect, thanks guys

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

Lee J. pisze:

I want, 03:45:08

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

Google strftime

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs