PHP Time function usage Analysis _php techniques

Source: Internet
Author: User
Tags local time php database php programming php regular expression string format

This article describes the PHP time function usage. Share to everyone for your reference, specific as follows:

PHP has a UNIX timestamp related operation function, easy to use

Time () returns the current Unix timestamp

Microtime--Returns the current Unix timestamp and microsecond number

Example 1. To run a 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 while
usleep (MB);
$time _end = Microtime_float ();
$time = $time _end-$time _start;
echo "Did Nothing in $time seconds/n";
? >

Mktime () to get a date on a Unix timestamp

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

Parameters can be omitted from right to left, and any omitted arguments will be set at the cost of the current value of the date and time

Date () format a local time/date

String date (string format [, int timestamp])

Tip: The timestamp that originated at the time of the request was saved from PHP 5.1 in $_server[' Request_time '.

strtotime--Resolves a date-time description of any English text to a Unix timestamp

Echo strtotime ("+1 Day"), "n";
Echo strtotime ("+1 Week"), "n";

Example 2. After a certain time of day, after month

Strtotime ("+1 Day". $day);
Strtotime ("2008-01-31 +1 Month");
Strtotime ($day. "+1 Day");

The above form is correct

PS: This site also provides a UNIX timestamp conversion tool, very practical, to provide you with reference to:

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

Here again for you to recommend a site for the layout of the PHP format landscaping tools to help you in the future of PHP programming code layout:

PHP code online format Landscaping tools:

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

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

C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json

More interested in PHP related content readers can view the site topics: "PHP Math Arithmetic Skills summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP Array" operation Skills Encyclopedia, " Summary of the PHP sorting algorithm, "PHP commonly used traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and " A summary of common PHP database operations tips

I hope this article will help you with the PHP program design.

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.