Ruby Time类和Date类
Time类
| 年月日时分秒,时区 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 生成 |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 获取属性的值 | t = Time.new()
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 比较 | t1 = Time.new() t2 = Time.mktime(2018, 1, 1) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 输出 | t.to_s() t.strftime(format)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 转换 |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| time库 | require "time" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 邮件日期格式 | t.rfc2822() Request For Comments 的RFC2822而来 Mon, 22 May 2017 02:39:13 +0900 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 国际标准表示 | t.iso8601() 2017-05-22T02:39:13+09:00 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 文字转日期 |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 年月日 | |||||||||||
| require "date" | |||||||||||
| 生成 |
|
||||||||||
| 运算 |
|
||||||||||
| 输出 | t.to_s() t.strftime("%Y/%m/%d") |
||||||||||
| 转换 |
|
||||||||||
| Data/Time相关的有用的方法 | |
| yesterday | 昨天 |
| tomorrow | 明天 |
| prev_xxxx | 前年/月/周(year,month,week) |
| next_xxxx | 下年/月/周(year,month,week) |
| beginning_of_xxxx | 年/季/月/周的开始一天(year, quarter, month, day) |
| end_of_xxxx | 年/季/月/周的最后一条(year, quarter, month, day) |
| n.xxx.ago Numeric |
n个年/月/日/时/分/秒以前 years, months, days, hours, minutes, seconds 也可以用单数 |
| n.xxx.from_now Numeric |
n个年/月/日/时/分/秒以后 years, months, days, hours, minutes, seconds 也可以用单数 |
Ruby Time类和Date类的更多相关文章
- Math类、Random类、System类、BigInteger类、BigDecimal类、Date类、SimpleDateFormat、Calendar类
Math类* A:Math类概述 * Math 类包含用于执行基本数学运算的方法,如初等指数.对数.平方根和三角函数. * B:成员方法 * public static int abs(int a) ...
- ruby Time类与Date类
Time类用于表示时间.时间除了表示年月日时分秒的信息外,还包含了表示地域时差的时区(time zone)信息.例如我们可以计算中国当前时间是国际协调时间的几点 Date类只用于表示年月日.因此,相对 ...
- 14-03 java BigInteger类,BigDecimal类,Date类,DateFormat类,Calendar类
BigInteger类 发 package cn.itcast_01; import java.math.BigInteger; /* * BigInteger:可以让超过Integer范围内的数据进 ...
- 正则表达式、Calendar类、SimpleDateFormat类、Date类、BigDecimal类、BigInteger类、System类、Random类、Math类(Java基础知识十四)
1.正则表达式的概述和简单使用 * A:正则表达式(一个字符串,是规则) * 是指一个用来描述或者匹配一系列符合某个语法规则的字符串的单个字符串.其实就是一种规则.有自己特殊的应用. * B: ...
- 处理时间的类 —— System类、Date类 、SimpleDateFormat类 与 Calendar类
在我们以往的编程中,就有过通过运行前和运行后时间差来判断时间复杂度的例子,再扯得远一点,我们在C语言中制造随机数的操作,也要用到有关时间的函数.而且,在我们未来的编程中,也会时不时要用到能够读取当前时 ...
- 时间日期相关类:Date类,DateFormat类&SimpleDateFormat类,Calendar类
日期相关类 1.Date类:日期时间类 A.构造方法 Date(): 根据当前系统时间创建日期对象 Date(Long time):根据传入的毫秒值时间创建日期对象 B.成员方法 Long get ...
- Object类、Date类、Calendar类、System类、StringBuilder类和基本类型包装类
一.Object类--toString方法 1.普通类重写toString方法,不然打印出来是存在栈内存的对象引用名称的堆内存中该对象的地址值: 2.equals方法: String比较equals是 ...
- C++实现日期类(Date类)
#include<iostream>using namespace std;class Date{public: Date(int year = 1900, int month = ...
- String类与Date类的转换
public class DateTest { public static void main(String[] args) throws ParseException { Date date = n ...
随机推荐
- 【转载】js中对象的使用
原文链接:http://www.jb51.net/article/90256.htm[侵删] 简单记录javascript中对象的使用 一.创建对象 //创建一个空对象 var o={}; //创建一 ...
- Drainage Ditches--hdu1532(网络流 模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/Other ...
- 实现浏览器兼容的innerText
今天学习到了FF不支持innerText,而IE.chrome.Safari.opera均支持innerText. 为了各个浏览器能兼容innerText,必须对js做一次封装. 为啥能实现兼容呢?原 ...
- 包装类Float中为什么有两个常量来表示最小值
1)问:包装类Float中为什么有两个常量来表示最小值:MIN_VALUE和MIN_NORMAL ① MIN_VALUE:最小正非零值常量,是非规格化浮点数所能表示的最小值.值为 3.4E-45 的常 ...
- jQuery的一些总结(持续更新中...)
本文为原创,转载请注明出处: cnzt 文章:cnzt-p http://www.cnblogs.com/zt-blog/p/6693399.html 1. $.expr[':'] 过滤 ...
- 报错: The type ByteInputStream is not accessible due to restriction on required library
报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...
- 从壹开始前后端分离【重要】║最全的部署方案 & 最丰富的错误分析
缘起 哈喽大家好!今天是周一了,这几天趁着午休的时间又读了一本书<偷影子的人>,可以看看
- 系统安全攻防战:DLL注入技术详解
DLL注入是一种允许攻击者在另一个进程的地址空间的上下文中运行任意代码的技术.攻击者使用DLL注入的过程中如果被赋予过多的运行特权,那么攻击者就很有可能会在DLL文件中嵌入自己的恶意攻击代码以获取更高 ...
- [Angular] Write Compound Components with Angular’s ContentChild
Allow the user to control the view of the toggle component. Break the toggle component up into multi ...
- 解决echart在IE中使用时,在div中加入postion后图表不显示问题
<!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style="height:400px;width:1 ...