Tag: strftime

在ruby中转换日期格式需要一些帮助

以下是一些输出: Date.today => Mon, 25 Jun 2012 Date.today.to_formatted_s(:long_ordinal) => “June 25th, 2012” Date.today.strftime(‘%A %d, %B’) => “Monday 25, June” 现在我需要输出格式,即: Monday 25th, June or Thrusday, 1st, October 问题是to_formatted_s和strftime仅适用于日期和两者或它们返回字符串。 如何以我需要的方式获得输出。

Rails undefined方法`strftime’代表“2013-03-06”:String

我收到了错误 undefined方法`strftime’代表“2013-03-06”:String 尝试使用strftime从字符串2013-03-06正常显示日期(2013年6月3日星期日或类似的东西)。 在我的index.html.erb中执行此操作的行看起来像这样 我只是在学习Rails,所以我确信这只是一个愚蠢的初学者错误,任何帮助将不胜感激。 谢谢

如何在ruby中格式化日期以包含“rd”,如“3rd”

我想格式化一个日期对象,以便我可以显示诸如“7月3日”或“10月1日”之类的字符串。 我在Date.strftime中找不到生成“rd”和“st”的选项。 有人知道怎么做吗?