Addition and subtraction of time by php

Source: Internet
Author: User
The addition and subtraction operations on time convert the time to the unix timestamp, and then perform addition and subtraction operations, and then perform reverse operations, php has a function to convert the time in the string format to the unix timestamp. The following is a simple example to add or subtract time, convert Time to unix timestamp, then perform addition and subtraction, and then perform reverse operations, php has a function to convert the time in the string format to the unix timestamp. The following is a simple example:
// Set the default time zone to use. Available after PHP5.1
Date_default_timezone_set ('Asia/Chongqing '); // used in China
Echo date ("Y-m-d H: I: s"); // display the current time
// Simple time addition and subtraction
$ Tomorrow = mktime (0, 0, 0, date ("m"), date ("d") + 1, date ("Y"); // tomorrow
// The current result is a timestamp. it is formatted and displayed, and the following is the same
Echo date ("Y-m-d H: I: s", $ tomorrow );
$ Lastmonth = mktime (0, 0, 0, date ("m")-1, date ("d"), date ("Y"); // next month
$ Nextyear = mktime (0, 0, 0, date ("m"), date ("d"), date ("Y") + 1); // tomorrow
// Returns the current Unix timestamp.
Echo time ();
// Returns the current Unix timestamp and microsecond ()
Function microtime_float (){
List ($ usec, $ sec) = explode ("", microtime ());
Return (float) $ usec + (float) $ sec );
}
$ Time_start = microtime_float (); // Sleep for a while
Usleep (100 );
$ Time_end = microtime_float ();

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.