Home  >  Article  >  php教程  >  php强大的时间转换函数strtotime,php函数strtotime

php强大的时间转换函数strtotime,php函数strtotime

WBOY
WBOYOriginal
2016-06-13 08:46:041192browse

php强大的时间转换函数strtotime,php函数strtotime

使用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;
 

转换自然时间描述

//昨天
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;

完整的php时间描述文档可以参考 http://php.net/manual/zh/datetime.formats.relative.php

您可能感兴趣的文章:

  • PHP strtotime函数详解
  • php 深入理解strtotime函数的使用详解
  • PHP时间戳 strtotime()使用方法和技巧
  • php使用strtotime和date函数判断日期是否有效代码分享
  • PHP下获取上个月、下个月、本月的日期(strtotime,date)
  • php使用date和strtotime函数输出指定日期的方法
  • js模仿php中strtotime()与date()函数实现方法
  • PHP使用strtotime获取上个月、下个月、本月的日期
Statement:
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