PHP使用strtotime计算两个给定日期之间天数的方法_PHP

WBOY
Release: 2016-06-01 11:06:28
Original
766 people have browsed it

本文实例讲述了PHP使用strtotime计算两个给定日期之间天数的方法。分享给大家供大家参考。具体分析如下:

PHP的strtotime函数用于将任何英文文本的日期时间描述解析为Unix时间戳。这个函数将使用TZ环境变量(如果有的话)来计算时间戳。如果执行成功它返回一个时间戳,否则返回FALSE。在PHP 5.1.0之前,这个函数将返回-1。

$date1 = date('Y-m-d');
$date2 = '2005-03-01′;
$days = (strtotime() – strtotime()) / (60 * 60 * 24);
echo "Number of days since '2005-03-01′: $days";
Copy after login

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!