PHP date_diff() 函数

PHP 教程 · 2019-01-23 19:42:10

实例

计算两个日期间的差值:

<?php
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
?>

定义和用法

date_diff() 函数返回两个 DateTime 对象间的差值。

语法

date_diff(datetime1,datetime2,absolute);

参数 描述
datetime1 必需。规定一个 DateTime 对象。
datetime2 必需。规定一个 DateTime 对象。
absolute 可选。规定一个布尔值。TRUE 表示间隔/差值必须是正的。默认是 FALSE。

技术细节

返回值: 如果成功则返回一个 DateInterval 对象,表示两个日期间的差值。如果失败则返回 FALSE。
PHP 版本: 5.3+

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

The Seasoned Schemer

The Seasoned Schemer

Daniel P. Friedman、Matthias Felleisen / The MIT Press / 1995-12-21 / USD 38.00

drawings by Duane Bibbyforeword and afterword by Guy L. Steele Jr.The notion that "thinking about computing is one of the most exciting things the human mind can do" sets both The Little Schemer (form......一起来看看 《The Seasoned Schemer》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器