formatting dates and times

Discussion in 'Ruby' started by rtilley, Mar 14, 2006.

  1. rtilley

    rtilley Guest

    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?
     
    rtilley, Mar 14, 2006
    #1
    1. Advertising

  2. rtilley

    Guest

    Time.now.strftime('%Y-%m-%d')
     
    , Mar 14, 2006
    #2
    1. Advertising

  3. rtilley

    rtilley Guest

    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
     
    rtilley, Mar 14, 2006
    #3
  4. 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
     
    Daniel Harple, Mar 14, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    893
    Rob Schieber
    Sep 30, 2005
  2. =?Utf-8?B?bWF2cmlja18xMDE=?=

    SetAuthCookie works some times and fails some times?

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    544
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 23, 2006
  3. Rune Allnor

    Dates and times in C++

    Rune Allnor, Oct 18, 2009, in forum: C++
    Replies:
    9
    Views:
    733
    Jerry Coffin
    Oct 19, 2009
  4. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    222
    Mark Schupp
    Aug 9, 2004
  5. Paul
    Replies:
    19
    Views:
    235
Loading...

Share This Page