[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Time#now

Lee Jarvis

9/12/2007 11:11:00 PM

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

4 Answers

Marcin Mielzynski

9/12/2007 11:17:00 PM

0

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

Phlip

9/12/2007 11:25:00 PM

0

> 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

Lee Jarvis

9/13/2007 10:10:00 PM

0

Perfect, thanks guys
--
Posted via http://www.ruby-....

Eric Hodel

9/15/2007 8:11:00 AM

0

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

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

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