简体   繁体   中英

Converting string to ruby datetime

I have the following string as a date

Thu 17 Jan

I want to convert this to a ruby date time object (to save in the database). I have tried chronic , but without luck.

Can someone help me out, thanks in advance

No need for chronic. Simple Date will do.

require 'date'

s = 'Thu 17 Jan'

Date.parse(s) # => #<Date: 2013-01-17 ((2456310j,0s,0n),+0s,2299161j)>

You may also use:

 s = 'Thu 17 Jan'

 date = DateTime.parse(s)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM