[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

formatting dates and times

Brad Tilley

3/14/2006 12:25:00 AM

In Python, I do this to format date and time in a certain fashion.

q = time.strftime('%Y-%m-%d', time.localtime())
r = time.strftime('%H:%M:%S', time.localtime())

I am formatting by YYYY-MM-DD and HH:MM:SS (I keep dashes between the
YYYY MM DD and colons between HH MM SS.

How is this done in Ruby?

4 Answers

zakak

3/14/2006 12:31:00 AM

0

Time.now.strftime('%Y-%m-%d')

Tim Hunter

3/14/2006 12:32:00 AM

0

rtilley wrote:
> In Python, I do this to format date and time in a certain fashion.
>
> q = time.strftime('%Y-%m-%d', time.localtime())
> r = time.strftime('%H:%M:%S', time.localtime())
>
> I am formatting by YYYY-MM-DD and HH:MM:SS (I keep dashes between the
> YYYY MM DD and colons between HH MM SS.
>
> How is this done in Ruby?
>
ri Time#strftime

Brad Tilley

3/14/2006 12:36:00 AM

0

zakak@fastmail.net wrote:
> Time.now.strftime('%Y-%m-%d')
>

Thanks... I came across the answer soon after posting. I should research
more before posting!

Thanks again,
Brad

Daniel Harple

3/14/2006 12:38:00 AM

0


On Mar 14, 2006, at 1:28 AM, rtilley wrote:

> In Python, I do this to format date and time in a certain fashion.
>
> q = time.strftime('%Y-%m-%d', time.localtime())
> r = time.strftime('%H:%M:%S', time.localtime())
>
> I am formatting by YYYY-MM-DD and HH:MM:SS (I keep dashes between
> the YYYY MM DD and colons between HH MM SS.
>
> How is this done in Ruby?

See Time#strftime:

Time.new.strftime('%Y-%m-%d') -> "2006-03-14"

-- Daniel