Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RUBY中的日期格式_Ruby On Rails_Ruby_Rubygems - Fatal编程技术网

Ruby on rails RUBY中的日期格式

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

在RUBY中,我需要这样的格式

“2011年2月1日11.00”

。我试过这个

"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)