简体   繁体   中英

Rails Time.parse argument out of range

I'm passing a string to a Time.parse but seeing very interesting behavior, see excerpt from console:

2.1.2 :011 > Time.parse("10/10/2014 7 am")
=> 2014-10-10 07:00:00 -0700 

2.1.2 :010 > Time.parse("10/17/2014 7 am")
ArgumentError: argument out of range

What's the difference???

I'm always going to be parsing times that users input in the format of "MM/DD/YYYY H am/pm", so it's crucial that this doesn't break.

Time.parse的格式为d / m / y,而我在文档中找不到将其更改为m / d / y的方法,因此,我只是更改了输入格式。

慢性宝石是解决此问题的有用工具,您可以设置endian_presedence以执行所需的操作。

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