Date arithmetic is often used in writing code. Most of the time, for convenience, it is possible to simply add and subtract a timestamp:
$time = mktime (0, 0, 0, 8, _hour_later); $one = Date (' y-m-d h:i:s ', $time + 3600);
This is a simple code to get a timestamp after an hour, but if you zoom in to a unit above the day, is this timestamp really what you want?
For example, if you have a time stamp of 0 o ' Day, you want to know the time stamp of 0 o ' day after 5 days, simply add the time after 5*86400?
>> 2015-03-13 00:00:00
There seems to be no problem. But what about the people in a different place?
The time zone is set to Chicago Date_default_timezone_set (' America/chicago '); $time = mktime (0, 0, 0, 3, 8); $five _day_later = Date (' Y-m-d h:i:s ', $time + 5 * 86400); echo $five _day_later;
>> 2015-03-13 01:00:00
Why isn't it 0 o ' day after 5 days?
Of course, this key problem is in daylight saving time (the principle of specific daylight savings is not introduced, can be self-Baidu).
Workaround: Use the Strtotime function instead of adding and subtracting
The time zone is set to Chicago Date_default_timezone_set (' America/chicago '); $time = mktime (0, 0, 0, 3, 8); $five _day_later = Date (' Y-m-d h:i:s ', Strtotime (' +5 days ', $time)); Echo $five _day_later;
>> 2015-03-13 00:00:00
While this problem does not exist in time zones that do not have daylight savings, it does affect your expected results for time zones that have daylight savings.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above is about 1 days equals 86,400 seconds? , including the aspects of the content, want to be interested in PHP tutorial friends helpful.