【发布时间】:2012-11-07 08:32:00
【问题描述】:
我需要在变量中获取三个日期
今天从午夜开始,我有这个
t = Time.now.strftime("%Y-%m-%d 00:00:01") # 2012-11-19 00:00:01
昨天从午夜开始(即 00:00:00 到 23:59:59)
y1 = 2012-11-18 00:00:01
y2 = 2012-11-19 23:59:59
特别是我需要创建为字符串以在 gem 中使用的 y1 和 y2 变量。作为 ruby 的新手,我有点困惑,因为 Time.yesterday 似乎没有做我需要的事情
编辑
为此请务必包括
需要'active_support/all'
并确保为您的应用程序捆绑 gem。
使用:
@current = (Time.now).beginning_of_day.utc.strftime("%Y-%m-%d")
@yesterday = (Time.now - 1.day).beginning_of_day.utc.strftime("%Y-%m-%d")
@everything = (Time.now - 2.day).end_of_day.utc.strftime("%Y-%m-%d")
【问题讨论】:
标签: ruby-on-rails ruby strftime