1.Time与Date两个类的区别
前者是秒为单位,Date以天为单位
2.时间的获取
1. t = Time.new #获取当前时间
2. t = Time.now #获取当前时间
3. t.year
4. t.month
5. t.day
6. Time.mktime(2013,1,1,12,0,0) #根据指定时间创建时间对象
3.字符串中获取时间
1. Time.parse(str) #解析字符串返回时间对象
Date类
1.日期的获取
1. d = Date.today #获取日期对象
2. d.year
3. d.month
4. d.day
5. d = Date.new(2013,1,1) #根据指定日期创建Date对象
2.日期的格式化输出
1. d = Date.today
2. d.strftime("%Y/%m%d %H%: %M: %S")
#将日期按照参数的格式输出
3.从字符串中获取日期
1. Date.parse("S48.9.28") #1973.09.28