How can I use US-style dates in Rails using Ruby 1.9?

后端 未结 7 1907
攒了一身酷
攒了一身酷 2021-01-04 09:21

I\'m in the U.S., and we usually format dates as "month/day/year". I\'m trying to make sure that my Rails app, using Ruby 1.9, assumes this format everywhere, and

7条回答
  •  我在风中等你
    2021-01-04 10:10

    Another option is Chronic - http://chronic.rubyforge.org/

    You just need to set the endian preference to force only MM/DD/YYYY date format:

    Chronic::DEFAULT_OPTIONS[ :endian_precedence ] = [ :middle ]
    

    However the default for Chronic is the out-of-order US date format anyway!

提交回复
热议问题