开发者

Date Format In RUBY

Here, In RUBY I need a format of Like this

"February 1st 2011 11.00"

. I tried this on开发者_JAVA百科e

"Time.now.utc.strftime("%B %d %Y %R")"

But I need to format numerals with suffixes st, nd, rd, th etc. Please suggest something.


If you specifically want "February 1st 2011 11.00" you would need to add your own DATE_FORMATS and call that.

Time::DATE_FORMATS[:custom_ordinal] = lambda { |time| time.strftime("%B #{ActiveSupport::Inflector.ordinalize(time.day)} %Y %H.%M") }

puts Time.now.to_s(:custom_ordinal)
# February 28th 2011 02.12

If all you want is an ordinal date and "February 28th, 2011 02:12" works, then call Time.now.to_s(:long_ordinal)


Install gem activesupport, and use method ordinalize:

How do I format a date in ruby to include "rd" as in "3rd"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜