[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: calendar events

James Gray

9/2/2007 3:22:00 AM

On Sep 1, 2007, at 8:55 PM, Felix Windt wrote:

>> -----Original Message-----
>> From: list-bounce@example.com
>> [mailto:list-bounce@example.com] On Behalf Of Michael Linfield
>> Sent: Saturday, September 01, 2007 6:35 PM
>> To: ruby-talk ML
>> Subject: Re: calendar events
>>
>> just another quick question...if i wanted to put a string into a date
>> format such as the following:
>>
>>
>> res = []
>> array = ["2/14/2005",83,35,23]
>> res << array.grep(/2/\14/\2005/)
>>
>> # so now res has "2/14/2005" in it...how would i turn that into a --
>>
>> specdate = Date.new(2, 24, 2005)
>>
>> so i need 2/14/2005 turned into a date object, preferably not
>> having to
>> use the format of Date.new(year,day,month) ...id prefer to have it in
>> the format of month,day,year if possible :)
>>
>> much thanks!
>> --
>> Posted via http://www.ruby-....
>>
>
> Once you have a string containing the date separated by slashes,
> you can
> split the string on separators to parse the date parts into
> variables, and
> then use those to construct the date object.
>
> irb(main):001:0> month, day, year = "2/14/2005".split("/").collect{|i|
> Integer(i)}
> => [2, 14, 2005]
> irb(main):002:0>

You can go straight into the Date object:

>> require "date"
=> false
>> date = Date.strptime("2/14/2005", "%m/%d/%Y")
=> #<Date: 4906831/2,0,2299161>
>> date.to_s
=> "2005-02-14"

James Edward Gray II