加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Ruby年 – 月 – 上周日的日期

发布时间:2020-12-17 02:46:45 所属栏目:百科 来源:网络整理
导读:我需要以最后两个星期日的2014-01-20格式计算. 所以,last_sunday = 2014-01-20和most_recent_sunday = 2014-01-26. 我使用的是Rails 4.0和Ruby 2.0.我怎样才能得到这些日期? 解决方法 在轨道4: most_recent_sunday = Time.now.sunday.to_slast_sunday = Ti
我需要以最后两个星期日的2014-01-20格式计算.

所以,last_sunday = 2014-01-20和most_recent_sunday = 2014-01-26.

我使用的是Rails 4.0和Ruby 2.0.我怎样才能得到这些日期?

解决方法

在轨道4:

most_recent_sunday = Time.now.sunday.to_s

last_sunday =        Time.now.last_week.sunday.to_s

要使其达到您所追求的格式:

DateTime.parse(most_recent_sunday).strftime("%Y-%m-%d")

http://apidock.com/rails/v4.0.2/DateAndTime/Calculations/sunday
http://apidock.com/rails/v4.0.2/DateAndTime/Calculations/last_week

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读