1 day equals 86400 seconds?

Source: Internet
Author: User
Tags time zones
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.