Time#now

L

Lee Jarvis

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
 
M

Marcin Mielżyński

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
 
P

Phlip

Lee Jarvis pisze:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top