: This article mainly introduces how one day equals 86400 seconds ?, If you are interested in the PHP Tutorial, refer. Date operations are often used in code writing. In most cases, for convenience, it is likely to simply add and subtract a timestamp:
$time = mktime(0, 0, 0, 8, 28, 2015);$one_hour_later = date('Y-m-d H:i:s', $time + 3600);
This is a simple code for getting the timestamp after one hour. but if you zoom in to a unit greater than one day, is this really what you want?
For example, if you have a timestamp at a day, do you want to know the timestamp at a day after 5 days? simply add the time after 5*86400?
$time = mktime(0, 0, 0, 3, 8, 2015);$five_day_later = date('Y-m-d H:i:s', $time + 5 * 86400);echo $five_day_later;
>>2015-03-13 00:00:00
It seems that there is no problem. But what about people in another place?
// Set the time zone to date_default_timezone_set ('America/Chicago '); $ time = mktime (0, 0, 0, 3, 8, 2015 ); $ five_day_later = date ('Y-m-d H: I: S', $ time + 5*86400); echo $ five_day_later;
>>2015-03-13 01:00:00
Why not in five days?
Of course, this key problem lies in the timing (the principle of the specific timing is not introduced, you can Baidu ).
Solution: Use the strtotime function instead of subtraction.
// Set the time zone to date_default_timezone_set ('America/Chicago '); $ time = mktime (0, 0, 0, 3, 8, 2015 ); $ five_day_later = date ('Y-m-d H: I: S', strtotime ('+ 5 days', $ time); echo $ five_day_later;
>>2015-03-13 00:00:00
Although this problem does not exist in those time zones without timeout, it does affect your expected results.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
Which of the following is 1 day equals 86400 seconds ?, Including some content, hope to be helpful to friends who are interested in PHP tutorials.