php中DateTime、diff
手册地址:http://php.net/manual/en/dateinterval.format.php
$january = new DateTime('2010-01-01');
$february = new DateTime('2010-02-01');
$interval = $january->diff($february);
// %a will output the total number of days.
echo $interval->format('%R%a total days'). '<br/>';// +31 total days
// While %d will only output the number of days not already covered by the
// month.
echo $interval->format('%m month, %d days');// 1 month, 0 days
format格式化参数:
formatcharacter |
Description | Example values |
|---|---|---|
| % | Literal % | % |
| Y | Years, numeric, at least 2 digits with leading 0 | 01, 03 |
| y | Years, numeric | 1, 3 |
| M | Months, numeric, at least 2 digits with leading 0 | 01, 03, 12 |
| m | Months, numeric | 1, 3, 12 |
| D | Days, numeric, at least 2 digits with leading 0 | 01, 03, 31 |
| d | Days, numeric | 1, 3, 31 |
| a | Total number of days as a result of a DateTime::diff() or (unknown)otherwise | 4, 18, 8123 |
| H | Hours, numeric, at least 2 digits with leading 0 | 01, 03, 23 |
| h | Hours, numeric | 1, 3, 23 |
| I | Minutes, numeric, at least 2 digits with leading 0 | 01, 03, 59 |
| i | Minutes, numeric | 1, 3, 59 |
| S | Seconds, numeric, at least 2 digits with leading 0 | 01, 03, 57 |
| s | Seconds, numeric | 1, 3, 57 |
| R | Sign "-" when negative, "+" when positive | -, + |
| r | Sign "-" when negative, empty when positive | -, |
php中DateTime、diff的更多相关文章
- .NET中DateTime.Now.ToString的格式化字符串
.NET中DateTime.Now.ToString显示毫秒:DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") DateTime.N ...
- easyui datagrid中datetime字段的显示和增删改查问题
datagrid中datetime字段的异常显示: 使用过easyui datagrid的应该都知道,如果数据库中的字段是datetime类型,绑定在datagrid显式的时候会不正常显示,一般需要借 ...
- 解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题
问题背景: 在使用asp.net mvc 结合jquery esayui做一个系统,但是在使用使用this.json方法直接返回一个json对象,在列表中显示时发现datetime类型的数据在转为字符 ...
- C#中 DateTime , DateTime2 ,DateTimeOffset 之间的小区别 (转载)
闲来无事列了个表比对一下这3兄弟之间还是有一点差距的╮(╯_╰)╭ DateTime DateTime2 DateTimeOffset 日期范围 1753-01-01到 9999-12-31 00 ...
- SQL中DateTime转换成Varchar样式
SQL中DateTime转换成Varchar样式语句及查询结果:Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AMSelect ...
- python中datetime模块中datetime对象的使用方法
本文只讲述datetime模块中datetime对象的一些常用的方法,如果读者需要更多datetime模块的信息,请查阅此文档. datetime模块的对象有如下: timedelta date da ...
- C# WebAPI中DateTime类型字段在使用微软自带的方法转json格式后默认含T的解决办法
原文:C# WebAPI中DateTime类型字段在使用微软自带的方法转json格式后默认含T的解决办法 本人新手,在.Net中写WebAPI的时候,当接口返回的json数据含有日期时间类型的字段时, ...
- 解决python写入mysql中datetime类型遇到的问题
解决python写入mysql中datetime类型遇到的问题 刚开始使用python,还不太熟练,遇到一个datetime数据类型的问题: 在mysql数据库中,有一个datetime类型的字段用于 ...
- sql查询中datetime显示的格式为yyyy-DD-mm
datetime数据库中保存的形式为2008/9/29 星期一 上午 12:00:00,希望界面显示2008-09-29,则可以用到以下sql语句. ),kgrq, ),),jhjgrq, ),'/' ...
随机推荐
- OneAlert 携手 BearyChat(倍洽)快速构建 IT 运维 on-call 机制
OneAlert 是北京蓝海讯通科技股份有限公司旗下产品,中国第⼀个 SaaS 模式的免费的云告警平台,集成国内外主流监控/⽀撑系统,实现⼀个平台上集中处理所有 IT 事件,提升 IT 可靠性.并且能 ...
- 配置文件读取工具类--PropertiesUtil
/** * 属性工具类 * @author admin * 参考:https://www.cnblogs.com/doudouxiaoye/p/5693454.html */ public class ...
- [20170904]11Gr2 查询光标为什么不共享脚本.txt
[20170904]11Gr2 查询光标为什么不共享脚本.txt --//参考链接下面的注解脚本:https://carlos-sierra.net/2017/09/01/poors-man-scri ...
- 找Maven --> pom.xml --> groupId和artifactId的网站
http://mvnrepository.com/ 在此记录
- Install Google Chrome on Fedora 28/27, CentOS/RHEL 7.5 (在 fedora 28 等 上 安装 chrome)
今天在使用 fedora 安装 chrome 的时候遇到了问题,今天进行将安装过程进行记录下来.需要安装第三方软件仓库. 我们需要进行安装 fedora-workstation-repositorie ...
- Python基础知识:函数
1.定义函数和调用函数 #定义函数def def greet_user(username): '''简单的问候语''' print('Hello,%s!'%username) greet_user(' ...
- 路由交换02-----ARP协议
路由交换协议-----ARP ARP协议 ARP(Address Resolution Protocol),是根据IP地址获取MAC地址的一个TCP/IP协议,即将IP地址对应到物理地址,从而实现数据 ...
- javascript中获取元素尺寸
Javascript获取获取屏幕.浏览器窗口 ,浏览器,网页高度.宽度的大小 屏幕可用工作区宽度:window.screen.availHeight,和浏览器无关,屏幕相关屏幕可用工作区高度:wind ...
- Beta冲刺! Day4 - 砍柴
Beta冲刺! Day4 - 砍柴 今日已完成 晨瑶:追进度 昭锡:改主页UI(还在 永盛:完成大部分接口和接口文档,上线代码 立强:文章去广告,适配手机屏幕.第三方编辑器整合到记录模块. 炜鸿:完成 ...
- [Tomcat]The JRE_HOME environment variable is not defined correctly
在tomcat的bin目录下,双击startup.bat,闪一下,就没了,后来仔细看了一下黑屏闪的内容如下: the JRE_HOME environment variable is not defi ...