Summary of PHP time calculation problems_PHP tutorial

WBOY
Release: 2016-07-21 15:47:53
Original
1016 people have browsed it

The details are as follows:
1> If we know the start time and want to add or subtract a time to get a result time, we can use the following code

$time1='2008-10-1 12:30:30 ';
echo date('Y-m-d H:i:s',strtotime($time1)+30*60);//Pay attention to the case in quotation marks, the minute is i not m
Execution result: 2008- 10-01 13:00:30

2> If we want to calculate the difference between two times, we can use the following method:

$time1='2008-10-1 12:30 :30';
$time2='2008-10-1 13:45:30';
$diff=(strtotime($time2)-strtotime($time1))/60;
echo $ Time difference from time1.' to '.$time2.''.$diff.'minute';
Execution result: Time difference from 2008-10-1 12:30:30 to 2008-10-1 13:45:30 75 minutes

Summary: The basis of PHP time calculation is seconds. After grasping this rule, you can convert the time difference into minutes, hours, etc., making time calculation very simple and easy.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319850.htmlTechArticleThe details are as follows: 1. If we know the starting time, we need to add or subtract a time to get a result time, which can be used The following code $time1='2008-10-1 12:30:30'; echo date('Y-m-d H:i:s',strtotime($time1...
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