Ruby date conversion

S

Singeo

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
 
R

Robert Dober

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
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top