Ruby date conversion

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.

Thanks

On 4/30/07, Singeo [email protected] 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”

HTH
Robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs