我有以下问题: 我希望在特定时间获得昨天的时间戳。
到目前为止,我的目标是:
Time.local(Time.now.strftime("%Y"), Time.now.strftime("%m"), (Time.now.strftime("%d")-1), 23, 59, 59).tv_sec
我是Ruby的新手,所以这可能是我的Ruby代码看起来与PHP非常相似的原因:)
当我说我想在Ruby中使用这个PHP解决方案时,这可能是一个帮助:
mktime(23,59,59,date("m",time()),date("d",time()-86400),date("Y",time()));
答案 0 :(得分:4)
使用Activesupport是否有问题?
require 'active_support'
Date.yesterday.end_of_day # .to_i to get the timestamp in seconds
#=> Mon Nov 14 23:59:59 +0100 2011
答案 1 :(得分:2)
require 'date'
Date.today.to_time - 1 #=> 2011-11-14 23:59:59