Forum: Ruby Ruby date conversion

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8103dcf73c4b8a7abca71390c18eba0e?d=identicon&s=25 Singeo (Guest)
on 2007-04-30 11:40
(Received via mailing list)
Hi, I have a text file with dates stored in the following format:

30/04/07 16:52:00 +0800

I need to convert these dates to RFC-822 so the above would become:

Mon, 30 Apr 2002 16:52:00 +0800

Can someone help me with the Ruby code required to do this? I've bveen
trying to do it using Time.parse but with no success.

703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2007-04-30 12:48
(Received via mailing list)
On 4/30/07, Singeo <> wrote:
> Thanks
I do this as lazily as possible:

irb(main):009:0> x="30/04/07 16:52:00 +0800"
=> "30/04/07 16:52:00 +0800"
irb(main):010:0> y,rest = x.split(/\s+/,2)
=> ["30/04/07", "16:52:00 +0800"]
irb(main):011:0> s=Date.strptime(y,"%y/%m/%d")
=> #<Date: 4925197/2,0,2299161>
irb(main):024:0> s.strftime("%a, %d %b %y") << rest
=> "Sun, 07 Apr 3016:52:00 +0800"

This topic is locked and can not be replied to.