[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

convert string to Time?

Chris McMahon

1/31/2007 9:19:00 PM

How can I convert a string such as '2007-01-31 12:22:26' to a Time
object?

6 Answers

Paul Brannan

1/31/2007 9:30:00 PM

0

On Thu, Feb 01, 2007 at 06:20:08AM +0900, Chris McMahon wrote:
> How can I convert a string such as '2007-01-31 12:22:26' to a Time
> object?

irb(main):001:0> require 'time'
=> true
irb(main):002:0> Time.parse('2007-01-31 12:22:26')
=> Wed Jan 31 12:22:26 EST 2007


Ben Bleything

1/31/2007 9:32:00 PM

0

On Thu, Feb 01, 2007, Chris McMahon wrote:
> How can I convert a string such as '2007-01-31 12:22:26' to a Time
> object?

Yup! You want Time.parse: ri Time.parse

Ben

Tom Werner

1/31/2007 9:49:00 PM

0

Chris McMahon wrote:
> How can I convert a string such as '2007-01-31 12:22:26' to a Time
> object?
>
>

Chronic can do that and a whole lot more (in case you need to)!

require 'chronic'

Chronic.parse('2007-01-31 12:22:26')
=> Wed Jan 31 12:22:26 -0800 2007

Chronic.parse('today at 12:22.26')
=> Wed Jan 31 12:22:26 -0800 2007

http://chronic.rub...

Tom

Florian Aßmann

1/31/2007 10:48:00 PM

0

Look at http://whytheluckystiff.net/rub...

... see Time.mktime

... first you should split(' ') ya string and then split the result,
order da stuff and put it into mktime...


Am 31.01.2007 um 22:20 schrieb Chris McMahon:

> How can I convert a string such as '2007-01-31 12:22:26' to a Time
> object?
>
>


Kevin

2/1/2007 12:51:00 PM

0

On Jan 31, 5:47 pm, Florian Aßmann <florian.assm...@email.de> wrote:
> Look athttp://whytheluckystiff.net/rub...
>
> .. see Time.mktime
>
> .. first you should split(' ') ya string and then split the result,
> order da stuff and put it into mktime...
>
> Am 31.01.2007 um 22:20 schrieb Chris McMahon:
>
> > How can I convert a string such as '2007-01-31 12:22:26' to a Time
> > object?

the ruby-units gem also has a helper for this...

'2007-01-31 12:22:26'.to_time #=> Wed Jan 31 12:22:26 EST 2007

_Kevin

Christopher Brown

2/1/2007 3:25:00 PM

0


On 01 Feb 2007, at 2:55 PM, _Kevin wrote:

> On Jan 31, 5:47 pm, Florian Aßmann <florian.assm...@email.de> wrote:
>> Look athttp://whytheluckystiff.net/rub...
>>
>> .. see Time.mktime
>>
>> .. first you should split(' ') ya string and then split the result,
>> order da stuff and put it into mktime...
>>
>> Am 31.01.2007 um 22:20 schrieb Chris McMahon:
>>
>>> How can I convert a string such as '2007-01-31 12:22:26' to a Time
>>> object?
>
> the ruby-units gem also has a helper for this...
>
> '2007-01-31 12:22:26'.to_time #=> Wed Jan 31 12:22:26 EST 2007
>
> _Kevin
>
>
Time. parse seems to do the trick too...

irb(main):003:0> Time.parse("2007-01-31 12:22:26")
=> Wed Jan 31 12:22:26 SAST 2007