php中日期加减法运算实现代码_PHP

WBOY
Release: 2016-06-01 12:14:02
Original
862 people have browsed it

1、首先通过strtotime()获得日期的时间戳

2、获得N天前得时间戳,通过”当前时间戳 - N天的秒数 = N天前得时间戳“

3、对N天前得时间戳用date()函数进行格式转换

下例:获得2012-5-1号之前一天的日期
复制代码 代码如下:
//将时间点转换为时间戳
$date = strtotime('2012-5-1');
//输出一天前的日期,在时间戳上减去一天的秒数
echo date('Y-m-d',$date - 1*24*60*60);
?>

输出:2012-4-30

此外,time()函数获得当前日期的时间戳!

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