如何在 ruby 中格式化日期以包含“rd"如“第三" [英] How do I format a date in ruby to include "rd" as in "3rd"
本文介绍了如何在 ruby 中格式化日期以包含“rd"如“第三"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想格式化一个日期对象,以便我可以显示诸如3rd July"或1st October"之类的字符串.我在 Date.strftime 中找不到生成rd"和st"的选项.有人知道怎么做吗?
解决方案
我会回应其他人,但我只是鼓励你下载 activesupport
gem,这样你就可以将其用作图书馆.您不需要所有的 Rails 来使用 ordinalize
.
I want to format a date object so that I can display strings such as "3rd July" or "1st October". I can't find an option in Date.strftime to generate the "rd" and "st". Any one know how to do this?
解决方案
I'm going to echo everyone else, but I'll just encourage you to download the activesupport
gem, so you can just use it as a library. You don't need all of Rails to use ordinalize
.
% gem install activesupport ... % irb irb> require 'rubygems' #=> true irb> require 'activesupport' #=> true irb> 3.ordinalize #=> "3rd"
这篇关于如何在 ruby 中格式化日期以包含“rd"如“第三"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文