开发者

ROR + TodayDate in Different Format

If I have @today = Date.today.to_s, how do I convert @today into UTC (with the appropriate date only)? But the format should be like this : 2011-03-08 00:00:00

Acutally I am looking for Yesterday date开发者_StackOverflow中文版 also ??


This worked for me to get yesterday at time 00hr

Date.yesterday.to_time.utc.at_beginning_of_day
=> Sun Mar 06 00:00:00 UTC 2011


I don't know if its the correct way to do it but it works

ruby-1.9.2-p0 > Date.today.to_time.utc
 => 2011-03-07 18:15:00 UTC 

and for yesterday, you can subtract a day form today

(Date.today-1.day).to_time.utc
 => 2011-03-06 18:15:00 UTC


For Yesterday Date.

@date = Date.yesterday => Mon, 07 Mar 2011

@date.to_time.utc.strftime("%Y-%m-%d %H:%M:%S") => "2011-03-06 18:30:00"


This will do(%F - %Y-%m-%d and %T - %H:%M:%S)

Date.today.strftime("%F %T")
Date.yesterday.strftime("%F %T")

If you are particular about UTC time, you should do like this

(Time.now.utc).to_date.strftime("%F %T")
(Time.now.utc - 1.day).to_date.strftime("%F %T")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜