Convert string to Time?

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

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

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

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:

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

On Jan 31, 5:47 pm, Florian Aßmann removed_email_address@domain.invalid 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

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

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

On Wed, Apr 4, 2012 at 8:29 AM, naveen kumar removed_email_address@domain.invalid
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.

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.

Hi

How to parse time in string

“Friday February seventh, three thirty AM two thousand fourteen”