PHP Time Calculation problem Summary _php tutorial

Source: Internet
Author: User
Specific as follows:
1> as we know the start time, to add a time, to arrive at a result time, you can use the following code

$time 1 = ' 2008-10-1 12:30:30 ';
echo Date (' y-m-d h:i:s ', Strtotime ($time 1) +30*60);//Note the case in quotation marks, minute is I not M
Execution Result: 2008-10-01 13:00:30

2> if we want to calculate the difference of two time, we can use the following methods:

$time 1 = ' 2008-10-1 12:30:30 ';
$time 2 = ' 2008-10-1 13:45:30 ';
$diff = (Strtotime ($time 2)-strtotime ($time 1))/60;
echo $time 1. ' To '. $time 2. ' Time difference '. $diff. ' Minutes ';
Execution Result: 2008-10-1 12:30:30 to 2008-10-1 13:45:30 time difference 75 minutes

Summary: The basis of PHP time calculation is the second, grasp the law can be converted into minutes, hours, etc. can be, so that time calculation becomes very simple and easy.

http://www.bkjia.com/PHPjc/319850.html www.bkjia.com true http://www.bkjia.com/PHPjc/319850.html techarticle As follows: 1 if we know the start time, to add a time, to arrive at a result time, you can use the following code $time 1= ' 2008-10-1 12:30:30 '; Echo date (' y-m-d h:i:s ', Strtotime ($time 1 ...

  • 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.