PHP time and date functions, php date functions _ PHP Tutorial

Source: Internet
Author: User
Tags month name
PHP time and date functions are described in detail, and php date functions are described in detail. PHP time and date functions. php date functions are explained in detail. all functions in PHP are in the UNIX epoch, that is, they started in January 1, 1970. The date is the number of seconds from this time. For example, the PHP time and date functions and the php date functions

All functions in PHP are in the UNIX era, that is, since January 1, 1970.

The date is the number of seconds from this time.

When a function is called in seconds, it is treated as a timestamp.

Local time functions

1. string date (string format, inieger timestamp)

This function returns a time string controlled by string format.
For example:

<? Print (date ("Y, m, d"); // output current, year, month, and day. print (date ("Y, m, d,", 60*60*24*365*10); // output on April 9, January 1, 1980.?>

Maybe you will ask, why is there no timestamp? If the timestamp is null or is not written, the current timestamp is used.
The control operator of the year: Y --- four-digit year y --- two-digit year
Indicates the control operator of the month: m --- from month F --- English month name M --- abbreviated month name
Control operator for day: d --- date j in the month with 0 in front -- date without 0 in front
Indicates the control letter of the week: l -- English week D -- abbreviation of the week
The hour controller: h -- hour from 1 to 12 H --- hour from 0 to 23
Represents the Upper afternoon controller a --- am or pm A---AM or PM
Indicates the minute controller: I --- value 00-59
The number of days in a year: z -- the number of days in a year

2. array getdate (integer timestamp)

This function returns a matrix.
For example:

<?$current_date=getdate();print($current_date("hours"));print($current_date("minutes");print($current_date("seconds");?>

Note:
Element description
Hour in the 24-hour format
Date in mday month
Minutes
Month in the form of mon
Full name of month
Seconds
The number of weeks in the format of 0 to 6 for wday
Weekday
Year
0 timestamp is the number of seconds from January 1, January 1, 1970 to the present.
A date in the digit format of a year in yday

3. boolean checkdate (integer month, integer day, integer year)
This function checks whether the date is valid. for example:

<? If (checkdate (1980,) print ("date is valid! N ");?>

4. integer time ()

This function obtains the current timestamp. for example:

<? Print (time (); // output a large integer?>

5. integer mktime (integer hour, integer minutes, integer seconds, integer month, integer day, integer year)

This function returns the timestamp of the given date, that is, the number of seconds from January 1, January 1, 1970 to the present.
If a parameter is out of the range, this function can also be interpreted, for example, 13 months is the second year of January.
For example:

<? $ Currenthour = date ("H"); print ("50 hours later:"); print (date ("h: I A l F dS, Y ", mktime ($ currenthour + 50); print ("
N ");?>

6. string microtime ()

This function returns a string, in milliseconds of the current time + spaces + seconds starting from January 1, 1970

<?print("start:microtime()
n");for($index=0;$index<1000;$index++)print("good!");print("stop:microtime()
n");?>

Also, standard time functions of various Linwei governance

The above is all the content of this article. I hope you will like it.

All functions in PHP are in the UNIX era, that is, since January 1, 1970. The date is the number of seconds from this time. When a letter...

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.