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

后端 未结 7 1906
攒了一身酷
攒了一身酷 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:14

    Instead of using to_s for Date instances, get in the habit of using strftime. It takes a format string that gives you complete control over the date format.

    Edit: strptime gives you full control over the parsing by specifying a format string as well. You can use the same format string in both methods.

提交回复
热议问题