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, ),'/' ...
随机推荐
- Scoop及使用
scoop window的命令行安装程序管理工具 通常我们下载软甲需要从网上搜索软件并下载安装等一系列复杂麻烦的过程 现在有了scoop 等一系列包管理器的诞生,就是省去了上述繁琐的搜索 - 下载 - ...
- React 入门学习笔记整理(四)—— 事件
1.事件定义 React事件绑定属性的命名采用驼峰式写法,而不是小写. 如果采用 JSX 的语法你需要传入一个函数作为事件处理函数,而不是一个字符串(DOM元素的写法) 在类组件中定义函数,通过thi ...
- 实践:配置keepalived实现主备热备份功能
图: 配置文件: 主服务器的配置如下: global_defs { router_id NodeA}vrrp_instance VI_1 { state MASTER #设置为主服务器 interfa ...
- spring cloud 配置文件application.yml和bootstrap.yml 的定位,区别和联系总算是有一点明白了
最近在启用springcloud配置中心server的东西,在整理属性资源的时候,突然发现:用了这么久的springboot,为什么会配置两个属性文件同时存在(application.yml/prop ...
- maven(四):一个基本maven项目的pom.xml配置
继续之前创建的test项目,一个基本项目的pom.xml文件,通常至少有三个部分 第一部分,项目坐标,信息描述等 <modelVersion>4.0.0</modelVersion& ...
- 洗礼灵魂,修炼python(29)--装饰器(1)—>利用经典案例解析装饰器概念
前提必备 不急着进入正题,在前面函数作用域那一章介绍了闭包,全局变量局部变量,这里再看几个简单的闭包案例: 1):不带参数 注意: 1.这里的name属性是每个函数都有的,可以反馈函数名 2.temp ...
- python第六十天-----RabbitMQ
RabbitMQ消息队列:默认为消息轮循模式,按client端启动是顺序接收 server端 import pika connection = pika.BlockingConnection(pika ...
- python----运算符、布尔值
一.运算符: + - * / ** // % 1,. in ,not in 用法(判断某个东西是否在某个东西里面) name = '郑建文' 其中‘郑建文’是字符串, ‘郑’或‘建’或‘文’是一个 ...
- Lua 与C 交互之LUA_REGISTRYINDEX(3)
通常来说,C函数需要保留一些非局部的数据,也就是指那些超过他们作用范围的数据.C语言中我们使用全局变量或者static变量来满足这种需要.然而当你为Lua设计一个程序库的时候,全局变量和static变 ...
- scanf函数(初学者)
scanf函数称为格式输入函数,即按用户指定的格式从键盘上把数据输入到指定的变量之中. 1.scanf函数的一般形式:scanf函数是一个标准的库函数,它的函数原型在头文件“stdio.h”中,与pr ...