Summary of php time computing problems

Source: Internet
Author: User
Tags echo date
Recently, when I was learning PHP, a friend asked me about time computing. now I think of delphi and mssql computing functions, which are very convenient to use, however, no similar time computing functions were found in the php Manual. through the inspiration of the net text and self-testing, we still find a simple method to implement the following:
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.
Related Article

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.