Time Calculations
代码
- >> Time.days_in_month(2)
- => 28
- >> Time.now.seconds_since_midnight
- => 8709.840965
-
- # last_year, next_year, last_month, next_month
- >> Time.now.last_year
- => Sun Dec 18 02:25:59 -0800 2005
- >> Time.now.next_month
- => Thu Jan 18 02:26:41 -0800 2007
-
- # beginning_of_day, end_of_day, beginning_of_month, end_of_month
- # beginning_of_quarter, beginning_of_year
- >> Time.now.beginning_of_day
- => Mon Dec 18 00:00:00 -0800 2006
-
- # yesterday, tomorrow, next_week(day = :monday)
- >> Time.now.tomorrow
- => Tue Dec 19 02:28:01 -0800 2006
- >> Time.now.next_week(:friday)
- => Fri Dec 29 00:00:00 -0800 2006
-
- # valid symbol keys for #change:
- # year, month, mday, hour, min, sec, usec
- >> Time.now
- => Mon Dec 18 02:33:17 -0800 2006
- >> Time.now.change(:hour => 1)
- => Mon Dec 18 01:00:00 -0800 2006
-
- >> Time.now.in(5.days)
- => Sat Dec 23 02:34:59 -0800 2006
所有strftime方法中可用的格式化符号: ===================================================== %a 星期的缩写,如Wed %A 星期的全称,如Wednesday %U 本星期在全年中所属的周数 %W %H 小时(24小时制) %M 分钟 %S 秒 %I 小时(12小时制) %p PM 或 AM %b 月份的缩写,如 Jan %B 月份的全称,如 January %c 本地日期和时间,如 06/14/07 16:43:49 %d 日期 (1..31) %j 本日在一年中所属的天 (1..366) %m 月份 (1..12) %w 星期的数字形式 (0..6) %x 本地日期,如 06/14/07 %Y 本地时间,如 16:43:49 %y 2位的年份表示,如07 %Y 4位的年份表示,如2007 %Z 时区名,如"中国标准时间" %% 字面符号%
------------------------------------------------------------------------------
Range#to_s(:db)
代码
- >> (7.days.ago..1.day.ago).to_s(:db)
- => "BETWEEN '2006-12-11 02:06:50' AND '2006-12-17 02:06:50'"
|
请发表评论