Ruby on rails RUBY中的日期格式
在RUBY中,我需要这样的格式 “2011年2月1日11.00” 。我试过这个Ruby on rails RUBY中的日期格式,ruby-on-rails,ruby,rubygems,Ruby On Rails,Ruby,Rubygems,在RUBY中,我需要这样的格式 “2011年2月1日11.00” 。我试过这个 "Time.now.utc.strftime("%B %d %Y %R")" 但我需要使用后缀st、nd、rd、th等设置数字格式。请提供建议。安装gemactivesupport,并使用方法对其进行排序: 如果您特别想要“2011年2月1日11.00”,您需要添加自己的日期格式并调用它 Time::DATE_FORMATS[:custom_ordinal] = lambda { |time| time.strft
"Time.now.utc.strftime("%B %d %Y %R")"
但我需要使用后缀st、nd、rd、th等设置数字格式。请提供建议。安装gem
activesupport
,并使用方法对其进行排序
:
如果您特别想要“2011年2月1日11.00”,您需要添加自己的日期格式并调用它
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
如果你想要的只是一个有序的日期,并且“2011年2月28日02:12”有效,那么请拨打Time.now.to_s(:long_ordinal)