Forum: Ruby formatting dates and times

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
rtilley (Guest)
on 2006-03-14 02:30
(Received via mailing list)
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?
unknown (Guest)
on 2006-03-14 02:33
(Received via mailing list)
Time.now.strftime('%Y-%m-%d')
Daniel H. (Guest)
on 2006-03-14 02:40
(Received via mailing list)
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
rtilley (Guest)
on 2006-03-14 02:40
(Received via mailing list)
removed_email_address@domain.invalid 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
Timothy H. (Guest)
on 2006-03-14 03:04
(Received via mailing list)
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
This topic is locked and can not be replied to.