本文介绍了ROR + TodayDate以UTC格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有 @today = Date.today.to_s
,那么如何将 @today转换为UTC
(仅适用日期)?
这里我只需要日期例如2011-03-08即08年3月08日。请建议一下?
If I have @today = Date.today.to_s
, how do I convert @today into UTC
(with the appropriate date only)?Here I need is only date for example 2011-03-08 ie 08 March 2011. Please suggest something ?
急性我正在寻找昨天的日期?
Acutally I am looking for Yesterday date ??
推荐答案
您需要将其转换为时间
或者直接使用时间),然后调用 Time#utc
:
You'll need to convert it to a Time
object (or just use Time anyway) and then call Time#utc
:
irb > Time.now
=> Tue Mar 08 15:32:36 +1100 2011
irb > Time.now.utc
=> Tue Mar 08 04:32:40 UTC 2011
然后您可以格式化,但需要它: / p>
You can then format it however you need it:
irb > @today = Time.now.utc
=> Tue Mar 08 04:34:25 UTC 2011
irb > @today.strftime("%Y-%m-%d")
=> "2011-03-08"
这篇关于ROR + TodayDate以UTC格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!