用红宝石显示日期 [英] Display Date with ruby
本文介绍了用红宝石显示日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的日期20100816,它是整数日期。
This is my date 20100816 and it integer date.
如何将其显示为2010年8月16日?
How to display it like 08/16/2010?
推荐答案
您可以使用 Date.strptime
方法读取给定格式的日期和 strftime
以另一种格式打印出来:
You can use the Date.strptime
method to read a date in a given format and strftime
to print it out in another format:
require 'date'
intdate = 20100816
Date.strptime(intdate.to_s, "%Y%m%d").strftime("%m/%d/%Y")
#=> "08/16/2010"
这篇关于用红宝石显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文