关于Ruby格式化时间DateTime

本文是对2009年的[url=http://hlee.iteye.com/blog/386035]Time Date时间转换和格式化输出[/url]的一个小更新

当时说到一个格式化输出


DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d %H:%M:%S').to_s


现在,用到一个格式化输入,就是我们得到string是奇怪的时间格式,有的月份在前,有的月份在后,怎么parse的问题



str = "2010-12-02_12-10-26"
puts str
puts DateTime.strptime(str, "%Y-%m-%d_%H-%M-%S")

你可能感兴趣的:(RubyOnRails)