This article mainly introduces the method of obtaining the specific time of each time period through PHP programming, and analyzes the related operating skills of date and time operations based on the date and strtotime functions in the form of examples. Friends in need can refer to the following
The details are as follows:
<?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] ) */ ?>
The running results are as follows:
今天: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
Related recommendations:
How to implement programming in PHP to calculate whether two time periods have intersection
PHP MySQL Detailed explanation of data statistics optimization steps within a fixed time period
PHP combines with Redis to restrict users or IPs Number of visits during time period
The above is the detailed content of PHP method to obtain the specific time of each time period. For more information, please follow other related articles on the PHP Chinese website!