PHP编程获取各个时间段具体时间的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了PHP编程获取各个时间段具体时间的方法。分享给大家供大家参考,具体如下:

<?php
echo "今天:".date("Y-m-d")."<br>";
echo "昨天:".date("Y-m-d",strtotime("-1 day")), "<br>";
echo "明天:".date("Y-m-d",strtotime("+1 day")). "<br>";
echo "一周后:".date("Y-m-d",strtotime("+1 week")). "<br>";
echo "一周零两天四小时两秒后:".date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")). "<br>";
echo "下个星期四:".date("Y-m-d",strtotime("next Thursday")). "<br>";
echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>";
echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>";
echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>";
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>";
/*
strtotime()函数的作用是将日期时间描述解析为 Unix 时间戳
int strtotime ( string time [, int now] )
*/
?>

运行结果如下:

今天:2017-05-26
昨天:2017-05-25
明天:2017-05-27
一周后:2017-06-02
一周零两天四小时两秒后:2017-06-04 6:06:39
下个星期四:2017-06-01
上个周一:2017-05-22
一个月前:2017-04-26
一个月后:2017-06-26
十年后:2027-05-26

PS:这里再为大家推荐几款时间及日期相关工具供大家参考使用:

在线日期/天数计算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi

在线日期计算器/相差天数计算器:
http://tools.jb51.net/jisuanqi/datecalc

在线日期天数差计算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq

Unix时间戳(timestamp)转换工具:
http://tools.jb51.net/code/unixtime

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php日期与时间用法总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

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

相关文章

php使用curl并发减少后端访问时间的方法分析

本文实例讲述了php使用curl并发减少后端访问时间的方法。分享给大家供大家参考,具体如下: 在我们平时的程序中难免出现同时访问几个接口的情况,平时我们用curl进行访问的时候,一般都是...

PHP实现格式化文件数据大小显示的方法

本文实例讲述了PHP实现格式化文件数据大小显示的方法。分享给大家供大家参考。具体分析如下: 有时候我们需要在网页上显示某个文件的大小,或者是其它数据的大小数字。 这个数字往往从跨度很大,...

php 执行系统命令的方法

代码如下: 复制代码 代码如下:#include <stdio.h> #include <stdlib.h> #include <sys/types.h&g...

PHP静态方法和静态属性及常量属性的区别与介绍

PHP中若使用static关键字来修饰属性、方法,称这些属性、方法为静态属性、静态方法。static关键字声明一个属性或方法是和类相关的,而不是和类的某个特定的实例相关,因此,这类属性或...

解析如何去掉CodeIgniter URL中的index.php

CI默认的rewrite url中是类似这样的,例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就类似这样http://localhost/CodeIgniter...