Home Ruby 获得前一个周2,周三的时间点的办法:gemchronic
Post
Cancel

Ruby 获得前一个周2,周三的时间点的办法:gemchronic

参考:https://github.com/mojombo/chronic/

require 'chronic'

Time.now #=> Sun Aug 27 23:18:25 PDT 2006

Chronic.parse('tomorrow')
#=> Mon Aug 28 12:00:00 PDT 2006

Chronic.parse('monday', :context => :past)
#=> Mon Aug 21 12:00:00 PDT 2006

Chronic.parse('this tuesday 5:00')
#=> Tue Aug 29 17:00:00 PDT 2006

太好用了。

值得注意的是: this tuesday 表示 下一个tuesday 

last tuesday 才是上一个周二

This post is licensed under CC BY 4.0 by the author.