Php calculates the number of days, hours, minutes, seconds, and instance code of two time differences.

Source: Internet
Author: User

Php calculates the number of days, hours, minutes, seconds, and instance code of two time differences.

Php calculates the number of days, hours, minutes, And seconds in different time ranges.

In PHP, calculating the number of days, hours, minutes, And seconds in different time periods is not as convenient as other languages, but it is also very easy to understand the Time Representation Method in PHP. This article describes how to calculate the time difference in php. For more information about the coders, see.

Let's take a look at the following online example:

// $ Startdate indicates the start time and $ enddate indicates the end time. <? Php $ startdate = "11:50:00"; $ enddate = "12:12:12"; $ date = floor (strtotime ($ enddate)-strtotime ($ startdate)/86400 ); echo "Days different :". $ date. "Day <br/>"; $ hour = floor (strtotime ($ enddate)-strtotime ($ startdate) % 86400/3600); echo "hours of difference: ". $ hour. "hour <br/>"; $ minute = floor (strtotime ($ enddate)-strtotime ($ startdate) % 86400/60); echo "number of minutes of difference: ". $ minute. "Minutes <br/>"; $ second = floor (strtotime ($ endda Te)-strtotime ($ startdate) % 86400% 60); echo "seconds of Difference:". $ second. "seconds";?>

Whether it is the time type constructed by yourself using strings (converted by strtotime) or the time type obtained by using the system's time function, it is actually a variable with a long integer. Two such variables can obviously be used for subtraction.

After subtraction, the value is the number of seconds of the difference. If the number of seconds is the remainder of 86400 (the number of seconds in a day), the number of differences is obtained. If the modulo value is set to 86400 and the remainder value is set to 3600 s and 60 s, the related hours and minutes are obtained. If the modulo is set to 86400 and the modulo is set to 60, the number of seconds is returned.

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

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.