Php time computing problem summary _ PHP Tutorial

Source: Internet
Author: User
Summary of php time computing issues. Specific: 1 as we know the start time, to add or subtract a time, to get a result of time, you can use the following code $ time12008-10-112: 30: 30; echodate (Y-m-dH: i: s, strtotime ($ time1 details:
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 = '2017-10-1 12:30:30 ';
Echo date ('Y-m-d H: I: S', strtotime ($ time1) + 30*60); // pay attention to 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 = '2017-10-1 12:30:30 ';
$ Time2 = '2017-10-1 13:45:30 ';
$ Diff = (strtotime ($ time2)-strtotime ($ time1)/60;
Echo $ time1. 'to'. $ time2. 'time difference'. $ diff. 'mine ';
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.

If we know the start time and need to add or subtract a time to get a result time, we can use the following code $ time1 = '2017-10-1 12:30:30 '; echo date ('Y-m-d H: I: S', strtotime ($ time1...

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.