Home > Backend Development > PHP Tutorial > Summary of PHP time calculation problems_PHP tutorial

Summary of PHP time calculation problems_PHP tutorial

WBOY
Release: 2016-07-13 17:37:24
Original
924 people have browsed it

I was learning PHP recently, and a friend asked about time calculation. At this time, I thought of the calculation functions of delphi and mssql. They are very convenient to use, but I checked the PHP manual and found no similar time calculation. Function, through inspiration from online articles and own testing, I still find a simple way to implement it

The details are as follows:
1> If we know the start time, and we need 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 The time difference between $time1. and $time2..$diff.minutes ;
Execution result: The time difference from 2008-10-1 12:30:30 to 2008-10-1 13:45:30 is 75 minutes
Summary: The basis of PHP time calculation is seconds, grasp this After setting the rules, you can convert the time difference into minutes, hours, etc., making time calculation very simple and easy.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486593.htmlTechArticleI was learning PHP recently, and a friend asked about the calculation of time. At this time, I thought of the calculation functions of delphi and mssql. , they are all very convenient to use, but I checked the PHP manual and found no similar time calculation function...
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