手册地址: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. csharp:SMO run sql script

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. 微信 H5 支付流程以及一些坑

    原文:https://blog.niceue.com/front-end-development/wechat-h5-payment-process-as-well-as-some-pits.html ...

  3. 运行gulp项目报错:AssertionError: Task function must be specified。

    一.问题描述: gulp项目在本地windows 10机器上跑没有任何问题,但是放在centos 7虚拟机上跑报错:AssertionError: Task function must be spec ...

  4. Salesforce中的单点登录简介

    单点登录的定义 引自维基百科: 单点登录(英语:Single sign-on,缩写为 SSO),又译为单一签入,一种对于许多相互关连,但是又是各自独立的软件系统,提供访问控制的属性.当拥有这项属性时, ...

  5. 【转】pam_mysql - MySQL error (Can't connect to local MySQL server through socket

    转自:http://350201.blog.51cto.com/340201/1034672 参照 http://wjw7702.blog.51cto.com/5210820/936244博 主做的p ...

  6. Java并发编程(十一)线程池的使用

    1.new Thread的弊端如下: a. 每次new Thread新建对象性能差. b. 线程缺乏统一管理,可能无限制新建线程,相互之间竞争,及可能占用过多系统资源导致死机或oom. c. 缺乏更多 ...

  7. Android Java语法学习

    Activity中有一个名称叫onCreate的方法.该方法是在Activity创建时被系统调用,是一个Activity生命周期的开始. onCreate方法的参数savedInstanceState ...

  8. 转:SQL Server中服务器角色和数据库角色权限详解

    当几个用户需要在某个特定的数据库中执行类似的动作时(这里没有相应的Windows用户组),就可以向该数据库中添加一个角色(role).数据库角色指定了可以访问相同数据库对象的一组数据库用户. 数据库角 ...

  9. Dos烧录脚本

    Dos命令之前更改的太简单,现在加入判断是否进入fasboot模式和判断Android镜像是否存在:代码已经尽量简化成这样,dos命令功能还是比较不好用的,用了一下午的时间... @echo off ...

  10. ccf题库中2016年4月2日俄罗斯方块问题

    题目如下: 问题描述 俄罗斯方块是俄罗斯人阿列克谢·帕基特诺夫发明的一款休闲游戏. 游戏在一个15行10列的方格图上进行,方格图上的每一个格子可能已经放置了方块,或者没有放置方块.每一轮,都会有一个新 ...