2010-07-10 114 views

回答

0

为什么你想创建时,已经有插件的迷你日历参考和event_calendar事件显示caledar格式。

+0

因为我喜欢做我的方式而不是别人的方式我会很乐意看着它,把它撕开做我想做的事! – 2010-08-13 06:37:31

1

ActiveSupport(Rails框架的一部分,但可以单独使用)扩展标准库日期类的功能适合您的目的。如果你不已经安装了Rails,只是安装的ActiveSupport:

gem install activesupport 

然后在你的代码,你可以使用它像这样:

require 'rubygems' 
require 'active_support' 

# Get today's date 
today = Date.today 

# These are in the standard library Date class 
today.year 
=> 2010 
today.month 
=> 7 
today.day 
=> 10 
today.wday 
=> 6 

# These are added by ActiveSupport 
date = today.beginning_of_month 
=> Thu Jul 01 2010 
date.end_of_month 
=> Sat Jul 31 2010 
date.prev_month 
=> Tue, 01 Jun 2010 
date.next_month 
=> Sun, 01 Aug 2010 
date + 2.months 
=> Wed, 01 Sep 2010 
date - 2.months 
=> Sat, 01 May 2010 

有关详细信息,请参阅documentation

0

也结帐the cal gem。它只为你做基础知识,所以你可以专注于自己创建日历。例如确定日历中的日期(通常是前一个月的几天,当前月份的日期以及下个月的几天),并从周日之外的一周开始。

相关问题