⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 09 - finding the day of the week.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
def every_sunday(d1, d2)  # You can use 1.day instead of 60*60*24 if you're using Rails.  one_day = d1.is_a?(Time) ? 60*60*24 : 1  sunday = d1 + ((7-d1.wday) % 7) * one_day  while sunday < d2    yield sunday    sunday += one_day * 7  endenddef print_every_sunday(d1, d2)  every_sunday(d1, d2) { |sunday| puts sunday.strftime("%x")}endprint_every_sunday(Time.local(2006, 1, 1), Time.local(2006, 2, 4))# 01/01/06# 01/08/06# 01/15/06# 01/22/06# 01/29/06#---t = Time.local(2006, 1, 1)t.strftime("%A %A %A!")                     # => "Sunday Sunday Sunday!"t.strftime("%a %a %a!")                     # => "Sun Sun Sun!"#---require 'date'module Week  def week    (yday + 7 - wday) / 7  endendclass Date  include Weekendclass Time  include Weekendsaturday = DateTime.new(2005, 1, 1)saturday.week                                    # => 0(saturday+1).week                                # => 1   #Sunday, January 2(saturday-1).week                                # => 52  #Friday, December 31#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -