Application of time and date of PHP development

Source: Internet
Author: User
Tags time and date

1, compare the size of two dates
Compare the size of two dates, first by converting the date to a timestamp, and then comparing the timestamp.
The sample code is as follows:

<?php$time 1=date ("y-m-d h:i:s");$time 2="2009-12-9 4:40:12";Echo "Time variable \ $time 1 of the time is:".$time 1."\ n";Echo "Time variable \ $time 2 of the time is:".$time 2."\ n";if(Strtotime ($time 1)-strtotime ($time 2) <0){Echo "\ $time 1 before \ $time 2";}Else{Echo "\ $time 2 before \ $time 1";}?>

The results of the operation are as follows:

2, implementation of the page script run time
This is primarily accomplished using the Microtime () function, which returns the current UNIX timestamp and the number of microseconds. Returns a string formatted as msec sec. Where sec is the current Unix timestamp, msec is the number of microseconds.
The syntax format is as follows:
String Microtime (void)

The sample code is as follows:

<?php function run_time(){    List($msec,$sec) =explode (" ", Microtime ());//Use the explode () function to return two variables    return((float)$msec+ (float)$sec);//Returns the and of two variables}$start=run_time ();//Run Run_time () function for the first time for($i=0;$i<100000;$i++){}$end=run_time ();//Run the Run_time () function againEcho "Time to run:". ($end-$start)."\ n";?>

Application of time and date of PHP development

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.