站长资源脚本专栏

Ruby 取得指定月日期数的方法

整理:jimmy2025/2/26浏览2
简介代码如下:复制代码 代码如下:require 'date' day = Date.new(2008, 2, -1) end_of_month = day.strftime('%d').to_i year_and_month = day.strftime('%Y%m') for today in 1.

代码如下:
复制代码 代码如下:
require 'date'

day = Date.new(2008, 2, -1)
end_of_month = day.strftime('%d').to_i
year_and_month = day.strftime('%Y%m')
for today in 1..end_of_month do
p sprintf('%s%02d', year_and_month, today)
end

其他参考资料:
http://d.hatena.ne.jp/littlebuddha/20081023/1224744392
http://blog.ozacc.com/archives/001492.html
http://www.ftnk.jp/~fumi/cl/2005-10-14-6.html
http://www.namaraii.com/rubytips/?%C6%FC%C9%D5%A4%C8%BB%FE%B9%EF