Recently learning PHP, a friend asked the time of the calculation, at this time I thought of the Delphi and MSSQL computing functions, they are very convenient to use, but check the PHP manual did not find a similar time calculation function, through the web-inspired and self test, or find a simple way to achieve
Specifically as follows:
1> as we know the start time, we need to add a time to get a result time, you can use the following code
$time 1 = ' 2008-10-1 12:30:30 ';
echo Date (' y-m-d h:i:s ', Strtotime ($time 1) +30*60);/note the case within quotation marks, the minute is I not M
Implementation result: 2008-10-01 13:00:30
2> if we want to calculate the difference of two times, you can use the following methods:
$time 1 = ' 2008-10-1 12:30:30 ';
$time 2 = ' 2008-10-1 13:45:30 ';
$diff = (Strtotime ($time 2)-strtotime ($time 1))/60;
echo $time 1 ' to '. $time 2 ' time difference '. $diff. ' Minutes ';
Results: 2008-10-1-12:30:30 to 2008-10-1 13:45:30 's jet lag is 75 minutes.
Summary: PHP time calculation is based on the second, grasp this rule can be converted into minutes, hours and so on, so that time calculation becomes very simple and easy.