Recently, when I was learning PHP, a friend asked me about time computing. Now I think of the calculation functions of delphi and mssql, which are very convenient to use, however, no similar time computing functions were found in the php manual. Through the inspiration of the net text and self-testing, we still find a simple method to achieve this.
The details are as follows:
1> if we know the start time, we need to add or subtract a time to get a result time, you can use the following code
$ Time1 = 12:30:30;
Echo date (Y-m-d H: I: s, strtotime ($ time1) + 30*60); // note the case in the quotation marks. The minute is that I is not m
Execution result: 13:00:30
2> to calculate the difference between the two time points, use the following method:
$ Time1 = 12:30:30;
$ Time2 = 13:45:30;
$ Diff = (strtotime ($ time2)-strtotime ($ time1)/60;
Echo $ time1. to. $ time2. time difference. $ diff. minute;
Result: The time difference between 12:30:30 and 13:45:30 is 75 minutes.
Summary: php time computing is based on seconds. After grasping this rule, the time difference can be converted to minutes or hours, making time computing very simple and easy.