Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
date formatting bug?
R. Mark Volkmann
4/10/2009 3:04:00 PM
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-...
.
1 Answer
matt
4/10/2009 3:31:00 PM
0
Mark Volkmann <mark@ociweb.com> 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 = matt@tidbits.com,
http://www.tidbits...
Leopard -
http://www.takecontrolbooks.com/leopard-custom...
AppleScript -
http://www.amazon.com/gp/product/...
Read TidBITS! It's free and smart.
http://www.t...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
date formatting bug?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password