php中DateTime、diff
2016-03-03 19:18
716 查看
手册地址: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 | -, |
相关文章推荐
- V-Play 文档翻译 ListPage
- (5) PHP 随笔---Smarty模板引擎 使用成熟的Smarty模板 05
- (4) PHP 随笔---Smarty模板引擎MiniSmarty及其优化 03-04
- (3) PHP 随笔---Smarty模板引擎技术基础+MiniSmarty 01-02
- (2) PHP 随笔---跟老韩学(36-38)---PHP基础(变量,基本语法)
- php socket 模型及效率问题
- 深入浅出讲解:php的socket通信
- php cookie 和 cookie跨域访问
- php依赖管理工具Composer的安装和使用
- mac下快速安装gearman和php扩展
- PHP实现登录,注册,密码修改
- BeanPostProcessor使用心得
- php web 信息采集
- 史上最详细的vsftpd配置文件讲解
- php读取大文件的方法
- ./upload/forum.php
- php分享二十九:命名空间
- laravel服务l队列资料整理
- thinkPHP使用函数时字符串中不能含有管道符”|“,否则报错;
- PHP的五种常见设计模式