手册地址: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格式化参数:


The following characters are recognized in the format parameter string. Each format character must be prefixed by a percent sign (%).
formatcharacter Description Example values
% Literal % %
Y Years, numeric, at least 2 digits with leading 0 0103
y Years, numeric 13
M Months, numeric, at least 2 digits with leading 0 010312
m Months, numeric 1312
D Days, numeric, at least 2 digits with leading 0 010331
d Days, numeric 1331
a Total number of days as a result of a DateTime::diff() or (unknown)otherwise 4188123
H Hours, numeric, at least 2 digits with leading 0 010323
h Hours, numeric 1323
I Minutes, numeric, at least 2 digits with leading 0 010359
i Minutes, numeric 1359
S Seconds, numeric, at least 2 digits with leading 0 010357
s Seconds, numeric 1357
R Sign "-" when negative, "+" when positive -+
r Sign "-" when negative, empty when positive -,

php中DateTime、diff的更多相关文章

  1. .NET中DateTime.Now.ToString的格式化字符串

    .NET中DateTime.Now.ToString显示毫秒:DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") DateTime.N ...

  2. easyui datagrid中datetime字段的显示和增删改查问题

    datagrid中datetime字段的异常显示: 使用过easyui datagrid的应该都知道,如果数据库中的字段是datetime类型,绑定在datagrid显式的时候会不正常显示,一般需要借 ...

  3. 解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题

    问题背景: 在使用asp.net mvc 结合jquery esayui做一个系统,但是在使用使用this.json方法直接返回一个json对象,在列表中显示时发现datetime类型的数据在转为字符 ...

  4. C#中 DateTime , DateTime2 ,DateTimeOffset 之间的小区别 (转载)

    闲来无事列了个表比对一下这3兄弟之间还是有一点差距的╮(╯_╰)╭   DateTime DateTime2 DateTimeOffset 日期范围 1753-01-01到 9999-12-31 00 ...

  5. SQL中DateTime转换成Varchar样式

    SQL中DateTime转换成Varchar样式语句及查询结果:Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AMSelect ...

  6. python中datetime模块中datetime对象的使用方法

    本文只讲述datetime模块中datetime对象的一些常用的方法,如果读者需要更多datetime模块的信息,请查阅此文档. datetime模块的对象有如下: timedelta date da ...

  7. C# WebAPI中DateTime类型字段在使用微软自带的方法转json格式后默认含T的解决办法

    原文:C# WebAPI中DateTime类型字段在使用微软自带的方法转json格式后默认含T的解决办法 本人新手,在.Net中写WebAPI的时候,当接口返回的json数据含有日期时间类型的字段时, ...

  8. 解决python写入mysql中datetime类型遇到的问题

    解决python写入mysql中datetime类型遇到的问题 刚开始使用python,还不太熟练,遇到一个datetime数据类型的问题: 在mysql数据库中,有一个datetime类型的字段用于 ...

  9. sql查询中datetime显示的格式为yyyy-DD-mm

    datetime数据库中保存的形式为2008/9/29 星期一 上午 12:00:00,希望界面显示2008-09-29,则可以用到以下sql语句. ),kgrq, ),),jhjgrq, ),'/' ...

随机推荐

  1. 元素的class和id问题

    一个元素有且只能有1个id,且全文中此id只能出现在一个元素上   一个元素不能写多次class,比如 <div class="a" class="b"& ...

  2. Sql Server 向上取整、向下取整、四舍五入取整

    ==================================================== [四舍五入取整截取] select round(55.56,0) ============== ...

  3. MySQL 性能优化--优化数据库结构之优化数据大小

    MySQL性能优化--优化数据库结构之优化数据大小   By:授客  QQ:1033553122 尽量减少表占用的磁盘空间.通常,执行查询期间处理表数据时,小表占用更少的内存. 表列 l   尽可能使 ...

  4. Linux笔记(二): WIN 10 Ubuntu 双系统

    (一)  说明 记录一次ubuntu安装过程及遇到的问题. 环境:WIN 10 单硬盘 (二)  ubuntu ISO文件下载 ubuntu 18.04 https://www.ubuntu.com/ ...

  5. 利用奇异值分解(SVD)进行图像压缩-python实现

    首先要声明,图片的算法有很多,如JPEG算法,SVD对图片的压缩可能并不是最佳选择,这里主要说明SVD可以降维 相对于PAC(主成分分析),SVD(奇异值分解)对数据的列和行都进行了降维,左奇异矩阵可 ...

  6. cropper实现基本的裁剪图片并上传

    使用cropper之前需要先引用 cropper.css 和 cropper.js cropper 官网:https://fengyuanchen.github.io/cropper/ cropper ...

  7. January 08th, 2018 Week 02nd Monday

    To be yourself in a world that is constantly trying to make you something else is the greatest accom ...

  8. Ulua对象管理方式

    不管是C++中还是在C#中,在都绕不开一个问题:类对象怎么在Lua中使用的问题,还好Lua提供了Userdata以及ligh Userdata结构类型,通过扩展可以处理这方面的问题.现在的很多框架也大 ...

  9. Alpha版本 - 展示博客

    Alpha版本 - 展示博客 S.W.S.D 成员简介 演示动态图 注册 登录 新建记录 分享记录 修改主页时间查看记录 文章模块 流星模块 修改用户信息(以头像为例) 用户使用概况 预期的典型用户 ...

  10. Spring MVC中自定义拦截器的简单示例

    1. 引言 拦截器(Interceptor)实现对每一个请求处理前后进行相关的业务处理,类似于Servlet的Filter. 我们可以让普通的Bean实现HandlerIntercpetor接口或继承 ...