开发者

Ruby DateTime format: How can I get 1st, 2nd, 3rd, 4th?

开发者 https://www.devze.com 2023-01-16 02:05 出处:网络
First of all, it doesn\'t seem that the DateTime format variables are documented anywhere so a +1 to anyone who can show this to me in rubydocs. Second of all, when looking at the Date.strftime functi

First of all, it doesn't seem that the DateTime format variables are documented anywhere so a +1 to anyone who can show this to me in rubydocs. Second of all, when looking at the Date.strftime function code, I don't开发者_如何学C see anything that can let me do something like:

Thursday, September 9th 2010

Does anyone know if this is possible?


You might want to take a look here.

To summarize

time = DateTime.now
time.strftime("%A, %B #{time.day.ordinalize} %Y")

Note that you are running in plain Ruby (2.0) you'll need to call:

require 'active_support/core_ext/integer/inflections'


You can found all means %xx in Time documentation

http://ruby-doc.org/core/classes/Time.html#M000298

So you just need made

date.strftime('%A, %B %d %Y')
0

精彩评论

暂无评论...
验证码 换一张
取 消