From: markonlinux@... Date: 2007-12-03T08:20:01+09:00 Subject: Re: file renaming/parsing help Hi, On Dec 2, 7:44 pm, "Mike Mr." wrote: > First of all let me say that I am an absolute newb when it comes to > rails. I am simply trying to work on an existing script that was > written by someone else. > > I need to take a filename that will always have a similar name and turn > it into an rfc2822 compliant line for an xml file. Here is what I have > so far but I am absolutely lost as you can see. sad > > The filenames will always be the same, e.g. November 15,2007.mp3 or > September 7,2008.mp3, etc. One thing I am concerned about is the day > since sometimes it will be a single digit and sometimes a double digit, > although I am sure their is a way around that too. > > I would love if someone could shed some light on this for me. I might > even learn something in the process. smile > > #The goal is turn "November 15,2007.mp3" into "Wed, 15 Nov 2007 19:00:00 > GMT" > # > #So far the output below gives me Wed, Nov15 > > filename = "November 15, 2007.mp3" > puts "Wed, " + ( filename[0,3]) + ( filename[-12,2]) > -- > Posted viahttp://www.ruby-forum.com/. not exactly what you're after (not sure how you intend to generate times?) but might help. require 'date' require 'time' str = "November 15, 2007.mp3" #str_sans_ext = str.split('.')[0] # or, str_sans_ext = str.gsub(/\.mp3/,'') new_date = Time.parse(str_sans_ext) puts new_date puts new_date.httpdate cheers, -- Mark