date formatting bug?

Discussion in 'Ruby' started by Mark Volkmann, Apr 10, 2009.

  1. Why does the year get changed in this code?

    require 'date'
    s = '2998-12-31'
    date = Date.parse(s)
    f = date.strftime('%d-%b-%G')
    puts f

    The output is 31-Dec-2999.
    This doesn't seem to happen with earlier years.
    This happens with Ruby 1.8.6 and JRuby 1.2.0RC2.
    --
    Posted via http://www.ruby-forum.com/.
     
    Mark Volkmann, Apr 10, 2009
    #1
    1. Advertising

  2. Mark Volkmann

    matt neuburg Guest

    Mark Volkmann <> wrote:

    > Why does the year get changed in this code?
    >
    > require 'date'
    > s = '2998-12-31'
    > date = Date.parse(s)
    > f = date.strftime('%d-%b-%G')


    It's because you asked for %G. If you wanted the actual year component
    of the date, you would have used %Y. man strftime...

    m.

    --
    matt neuburg, phd = , http://www.tidbits.com/matt/
    Leopard - http://www.takecontrolbooks.com/leopard-customizing.html
    AppleScript - http://www.amazon.com/gp/product/0596102119
    Read TidBITS! It's free and smart. http://www.tidbits.com
     
    matt neuburg, Apr 10, 2009
    #2
    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. Matt
    Replies:
    1
    Views:
    605
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,272
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    519
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    723
    Richard Heathfield
    Nov 8, 2003
  5. Matt
    Replies:
    11
    Views:
    407
    Aaron Bertrand [MVP]
    Nov 8, 2003
Loading...

Share This Page