# Time#now

**URL:** <https://rubytalk.org/t/time-now/40580>\
**Category:** ruby-talk\
**Created:** [12 September 2007 23:11 UTC](https://rubytalk.org/t/time-now/40580 "2007-09-12T23:11:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@Lee\_Jarvis](https://rubytalk.org/u/Lee_Jarvis)\
**Post date:** [12 September 2007 23:11 UTC](https://rubytalk.org/t/time-now/40580/1 "2007-09-12T23:11:26Z")

</div>

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/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Marcin\_Miel\_ynski](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Marcin\_Miel\_ynski](https://rubytalk.org/u/Marcin_Miel_ynski)\
**Post date:** [12 September 2007 23:20 UTC](https://rubytalk.org/t/time-now/40580/2 "2007-09-12T23:20:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [12 September 2007 23:25 UTC](https://rubytalk.org/t/time-now/40580/3 "2007-09-12T23:25:26Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![Lee\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@Lee\_Jarvis](https://rubytalk.org/u/Lee_Jarvis)\
**Post date:** [13 September 2007 22:10 UTC](https://rubytalk.org/t/time-now/40580/4 "2007-09-13T22:10:08Z")

</div>

Perfect, thanks guys

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [15 September 2007 08:11 UTC](https://rubytalk.org/t/time-now/40580/5 "2007-09-15T08:11:23Z")

</div>

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
