我有一个日期字符串,如下所示
(2013 年 1 月 29 日,星期二)
如何将其转换为 Date 对象?
require 'time'
dt = "( Tue, Jan 29, 2013)"
Time.parse(dt) #=> 2013-01-29 00:00:00 -0800
Date.parse(dt) #=> #<Date: 2013-01-29 ((2456322j,0s,0n),+0s,2299161j)>
require 'date'
dt=" ( Tue, Jan 29, 2013) "
Date.parse dt
# => #<Date: 2013-01-29 ((2456322j,0s,0n),+0s,2299161j)>
Date.parse(dt).to_s
# => "2013-01-29"