Php time function usage analysis, php function usage _ PHP Tutorial

Source: Internet
Author: User
Analysis of php time function usage and php function usage. Php time function usage analysis. This article describes the usage of php time functions. For your reference, refer to: Analysis on the usage of php time functions related to unix timestamps in php and the usage of php functions.

This example describes the usage of php time functions. We will share this with you for your reference. The details are as follows:

Functions related to unix timestamps in php are easy to use.

Time () returns the current Unix timestamp.

Microtime -- returns the current Unix timestamp and microseconds.

Example 1. run the script with microtime ()

<?php/*** Simple function to replicate PHP 5 behaviour*/function microtime_float(){  list($usec, $sec) = explode(" ", microtime());  return ((float)$usec + (float)$sec);}$time_start = microtime_float();// Sleep for a whileusleep(100);$time_end = microtime_float();$time = $time_end - $time_start;echo "Did nothing in $time seconds/n";?>

Mktime () gets the Unix timestamp of a date.

Int mktime ([int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst])

The parameter can be omitted from the right to the left. any omitted parameter is set to the current value of the local date and time.

Date () format a local time/date

String date (string format [, int timestamp])

Tip: Since PHP 5.1, the timestamp at which the REQUEST is initiated is saved in $ _ SERVER ['request _ time.

Strtotime -- parses the date and time descriptions of any English text into Unix timestamps

echo strtotime("+1 day"), "/n";echo strtotime("+1 week"), "/n";

Example 2. the last day of a certain time, and the last month

strtotime("+1 day ".$day);strtotime("2008-01-31 +1 month");strtotime($day." +1 day");

The above format is correct

PS: This site also provides a Unix timestamp conversion tool, which is very useful for your reference:

Unix timestamp conversion tool:
Http://tools.jb51.net/code/unixtime

We recommend a php formatting and formatting typographical tool on this site to help you typeset code in future PHP programming:

Php code online formatting and beautification tools:

Http://tools.jb51.net/code/phpformat

In addition, because php belongs to the C language style, the following tool can also format php code:

C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json

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.