Forum: Ruby convert string to Time?

Ea97ad3789541367331966f009f549cb?d=identicon&s=25 Chris McMahon (Guest)
on 2007-01-31 22:21
(Received via mailing list)
How can I convert a string such as '2007-01-31 12:22:26' to a Time
object?
Fe6a008c1e3065327d1f1b007d8f1362?d=identicon&s=25 Paul Brannan (cout)
on 2007-01-31 22:31
(Received via mailing list)
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
90a73d9875462aaa9fab2feffafbffe7?d=identicon&s=25 Ben Bleything (Guest)
on 2007-01-31 22:34
(Received via mailing list)
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
8f198eee78af8fee4e57ef7af7d583ae?d=identicon&s=25 Tom Werner (Guest)
on 2007-01-31 22:49
(Received via mailing list)
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.rubyforge.org

Tom
Ee469623eb1b8e6e35d192822b9c4aa2?d=identicon&s=25 Florian Aßmann (Guest)
on 2007-01-31 23:48
(Received via mailing list)
Look at http://whytheluckystiff.net/ruby/pickaxe/

... 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:
5f23b06d22b84ec6c902bf390071a79c?d=identicon&s=25 _Kevin (Guest)
on 2007-02-01 13:56
(Received via mailing list)
On Jan 31, 5:47 pm, Florian Aßmann <florian.assm...@email.de> wrote:
> > 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
0a98b50499e6e846f23756b7f4545ad6?d=identicon&s=25 Christopher Brown (Guest)
on 2007-02-01 16:25
(Received via mailing list)
On 01 Feb 2007, at 2:55 PM, _Kevin wrote:

>>> 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
1e2a6b76e96d7ad028c0733588bfda01?d=identicon&s=25 naveen kumar (naveenkumar)
on 2012-04-04 15:29
hi friends..i tring to scrape links using nokogiri gem..i using the
while loop,but the linkis not working properly to while loop the
condition is "status =404"..pls solve my problem
Abdb670e1c130f96f947a94d03c02efa?d=identicon&s=25 Eric Christopherson (echristopherson)
on 2012-04-05 22:37
(Received via mailing list)
On Wed, Apr 4, 2012 at 8:29 AM, naveen kumar <lists@ruby-forum.com>
wrote:
> hi friends..i tring to scrape links using nokogiri gem..i using the
> while loop,but the linkis not working properly to while loop the
> condition is "status =404"..pls solve my problem

You should use double equals in such a condition, e.g. `status ==
404`. Also, the library you're using to fetch web pages might not
store HTTP statuses as numbers; you might have to compare against the
string '404' instead.
98035f2826f1c962799e023da10d5f77?d=identicon&s=25 Kanna Vrk (kanna_v)
on 2014-04-29 20:50
Hi

How to parse time in string

"Friday February seventh, three thirty AM two thousand fourteen"
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-04-29 23:41
If the string is always in the same format you can scan it and convert
each section into the appropriate value before feeding it to Time.parse.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.