Ruby语言在实际应用中可以帮助我们轻松的完成许多功能需求。其内置的大量方法是我们实现功能的前提。下面我们为大家介绍其中Ruby时间方法的相关方法。#t#
创新互联专注于乌鲁木齐企业网站建设,成都响应式网站建设,商城建设。乌鲁木齐网站建设公司,为乌鲁木齐等地区提供建站服务。全流程按需定制设计,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
Ruby时间方法:
- puts 20.seconds #=> 20
- puts 20.minutes #=> 1200
- puts 20.hours #=> 72000
- puts 20.days #=> 1728000
- puts 20.weeks #=> 12096000
- puts 20.fortnights #=> 24192000
- puts 20.months #=> 51840000
- puts 20.years #=> 630720000
- puts Time.now #=> Thu May 18 23:29:14 CDT 2006
- puts 20.minutes.ago #=> Thu May 18 23:09:14 CDT 2006
- puts 20.hours.from_now #=> Fri May 19 19:29:14 CDT 2006
- puts 20.weeks.from_now #=> Thu Oct 05 23:29:14 CDT 2006
- puts 20.months.ago #=> Sat Sep 25 23:29:16 CDT 2004
- puts 20.minutes.until("2006-12-25 12:00:00".to_time)
- #=> Mon Dec 25 11:40:00 UTC 2006
- puts 20.minutes.since("2006-12-25 12:00:00".to_time)
- #=> Mon Dec 25 12:20:00 UTC 2006
- now = Time.now
- puts now #=> Thu May 18 23:36:10 CDT 2006
- puts now.to_date #=> 2006-05-18
- puts now.to_s #=> Thu May 18 23:36:10 CDT 2006
- puts now.to_s(:short) #=> 18 May 23:36
- puts now.to_s(:long) #=> May 18, 2006 23:36
- puts now.to_s(:db) #=> 2006-05-18 23:36:10
- puts now.to_s(:rfc822) #=> Thu, 18 May 2006 23:36:10 -0500
- puts now.ago(3600) #=> Thu May 18 22:36:10 CDT 2006
- puts now.at_beginning_of_day #=> Thu May 18 00:00:00 CDT 2006
- puts now.at_beginning_of_month #=> Mon May 01 00:00:00 CDT 2006
- puts now.at_beginning_of_week #=> Mon May 15 00:00:00 CDT 2006
- puts now.beginning_of_quarter #=> Sat Apr 01 00:00:00 CST 2006
- puts now.at_beginning_of_year #=> Sun Jan 01 00:00:00 CST 2006
- puts now.at_midnight #=> Thu May 18 00:00:00 CDT 2006
- puts now.change(:hour => 13) #=> Thu May 18 13:00:00 CDT 2006
- puts now.last_month #=> Tue Apr 18 23:36:10 CDT 2006
- puts now.last_year #=> Wed May 18 23:36:10 CDT 2005
- puts now.midnight #=> Thu May 18 00:00:00 CDT 2006
- puts now.monday #=> Mon May 15 00:00:00 CDT 2006
- puts now.months_ago(2) #=> Sat Mar 18 23:36:10 CST 2006
- puts now.months_since(2) #=> Tue Jul 18 23:36:10 CDT 2006
- puts now.next_week #=> Mon May 22 00:00:00 CDT 2006
- puts now.next_year #=> Fri May 18 23:36:10 CDT 2007
- puts now.seconds_since_midnight #=> 84970.423472
- puts now.since(7200) #=> Fri May 19 01:36:10 CDT 2006
- puts now.tomorrow #=> Fri May 19 23:36:10 CDT 2006
- puts now.years_ago(2) #=> Tue May 18 23:36:10 CDT 2004
- puts now.years_since(2) #=> Sun May 18 23:36:10 CDT 2008
- puts now.yesterday #=> Wed May 17 23:36:10 CDT 2006
- puts now.advance(:days => 30) #=> Sat Jun 17 23:36:10 CDT 2006
- puts Time.days_in_month(2) #=> 28
- puts Time.days_in_month(2, 2000) #=> 29
以上就是Ruby时间方法的相关知识讲解。
本文题目:Ruby时间方法概念总结
链接地址:http://www.csdahua.cn/qtweb/news21/305671.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
广告
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源:
快上网