php强大的时间转换函数strtotime_PHP

WBOY
Release: 2016-05-28 11:48:41
Original
957 people have browsed it

使用strtotime可以将各种格式的时间字符串转换为时间戳

转换常规时间格式

echo date('Y-m-d H:i:s', strtotime('2016-01-30 18:00')).PHP_EOL;
echo date('Y-m-d H:i:s', strtotime('20160130180001')).PHP_EOL;
 
Copy after login

转换自然时间描述

//昨天
echo date('Y-m-d H:i:s', strtotime('yesterday')).PHP_EOL;
//上周
echo date('Y-m-d H:i:s', strtotime('last week')).PHP_EOL;
//本周开始时间
echo date('Y-m-d H:i:s', strtotime('this week midnight')).PHP_EOL;
//本月开始时间
echo date('Y-m-d H:i:s', strtotime('first day of this month midnight')).PHP_EOL;
 
//计算相对时间
echo date('Y-m-d H:i:s', strtotime('+1 month')).PHP_EOL;
Copy after login

完整的php时间描述文档可以参考 http://php.net/manual/zh/datetime.formats.relative.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