PHP Date Function and PHP time function __ function

Source: Internet
Author: User
Tags echo date getdate month name string format time and date
Checkdate: Verify the correctness of the date.
Date: Format the time of the server.
Strftime: The time of the server is formatted locally.
GETDATE: Get time and date information.
Gettimeofday: Get the current time.
Gmdate: Gets the current time after the difference with GMT.
Easter_date: Calculates the Easter date.
Easter_days: Calculates the number of dates between Easter and March 21.
Mktime: Gets the Unix time stamp.
Gmmktime: Get the Unix time stamp GMT.
Time: Gets the Unix time stamp for the current time.
Microtime: The one out of 10,000-second value of the Unix time stamp that obtained the current time

Checkdate
Verify the correctness of the date.
Syntax: int checkdate (int month, int day, int year);
return value: Integer
Function Type: time date
Content Description Returns True if the date is valid, or False if the date is problematic. This function can be used to check whether the date is valid. The effective range is as follows:
Year of 0-32,767 years
Month is 1-12 months
The day changes with the month and leap year

Date
Format the time of the server.
Syntax: string date (string format, int [timestamp]);
return value: String
Function Type: time date
Content Description The string that returns the value is determined according to the configuration format. If there is an incoming timestamp value, the timestamp is formatted and returned, or the current server's time is formatted if there is no incoming timestamp value. To convert a date to another language format, use thesetlocale() and strftime () two functions. The options for formatting strings are as follows:
A-"AM" or "PM"
A-"AM" or "PM"
D-A few days, two digits, if less than two digits before the 0; such as: "01" to "31"
D-Days of the week, three English letters; such as: "Fri"
F-month, full name in English; such as: "January"
Hours of h-12 hours; such as: "01" to "12"
Hours of h-24 hours; such as: "00" to "23"
G-12 hours, less than two-bit not to fill 0; such as: "1" to 12 "
G-24 hours, less than two-bit not to fill 0; such as: "0" to "23"
I-minute; such as: "00" to "59"
J-A few days, two digits, if less than two digits do not fill 0; such as: "1" to "31"
L-Days of the week, full name in English; such as: "Friday"
M-month, two digits, if less than two digits in front of the 0; such as: "01" to "12"
N-month, two digits, if less than two digits will not fill 0; such as: "1" to "12"
M-month, three English letters; such as: "The"
S-seconds; such as: "00" to "59"
S-word tail plus English ordinal number, two English letters; such as: "th", "nd"
T-Specifies the number of days of the month; such as: "28" to "31"
U-Total number of seconds
W-Number of days of the week, such as: "0" (Sunday) to "6" (Saturday)
Y-year, four digits; such as: "1999"
Y-year, two digits; such as: "99"
Z-the day ordinal of the year; such as: "0" to "365"
Other characters that are not listed directly list the characters.

Usage examples
Example one:
Print (Date ("L DS of F y h:i:s a"));
Print ("July 1, are on a". Date ("L", Mktime (0,0,0,7,1,2000));
?>

Example two:
$tomorrow = Mktime (0,0,0,date ("M"), Date ("D") +1,date ("Y"));
$lastmonth = Mktime (0,0,0,date ("M") -1,date ("D"), date ("Y"));
$nextyear = Mktime (0,0,0,date ("M"), Date ("D", date ("Y") +1);
?>

Reference gmdate () mktime ()

Strftime
The time of the server is formatted locally.
Syntax: string strftime (string format, int [timestamp]);
return value: String
Function Type: time date
Content Description The string that returns the value is determined according to the configuration format. If there is an incoming timestamp value, the timestamp is formatted and returned, or the current server's time is locally formatted if there is no incoming timestamp value. The month or week name is configured with the local languagesetlocale() change in different ways.

The returned string can be determined in the following format:
%a the abbreviation of the week.
%a the full name of the week.
The abbreviation for the%b month name.
The full name of the%b month name.
%c Local End Date time is a better representation string.
%d numbers indicate the day of the month (range 00 to 31).
%h uses a 24-hour system number to indicate the number of hours (range 00 to 23).
%i uses a 12-hour system number to indicate the number of hours (range 01 to 12).
%j the number of days of the year (ranging from 001 to 366).
Number of%m months (ranging from 1 to 12).
%m minutes.
%p indicates the local end time with ' am ' or ' pm '.
%s Number of seconds.
The%u number is expressed as the week ordinal of the year, and the first one week begins in Sunday.
The%w number is expressed as the week ordinal of the year, and the first one week begins in Monday.
%w the number of days of the week (0 for Sunday).
%x does not contain a date representation of time.
%x does not contain a time representation of dates.
%y two digits indicates the year (range from 00 to 99).
%y full year digits, that is, four digits.
%z time zone or name abbreviation.
%%% character.

Usage examples
setlocale("Lc_time", "C");
Print (Strftime ("%a in Finnish is"));
setlocale("Lc_time", "fi");
Print (Strftime ("%a, in French"));
setlocale("Lc_time", "fr");
Print (Strftime ("%a and in German"));
setlocale("Lc_time", "de");
Print (Strftime ("%A.N"));
?>

Referencesetlocale() Mktime ()

GetDate
Get time and date information.
Syntax: array getdate (int timestamp);
return value: Array
Function Type: time date
Content description The elements that return an array include the following items:
"Seconds"-seconds
"Minutes"-min
"Hours"-when
"Mday"-Day of the month
"Wday"-the number of days of the week
"Mon"-month numbers
"Year"-years, numbers
"Yday"-Number of days of the year; such as: "299"
"Weekday"-full name of the week; such as: "Friday"
"Month"-month full name; such as: "January"

Gettimeofday
Get the current time.
Syntax: array gettimeofday (void);
return value: Array
Function Type: time date
Content description The elements that return an array include the following items:
"SEC"-sec
"USec"-one out of 10,000 seconds
"Minuteswest"-The Point of GMT
"Dsttime"-time zone for the purpose

Gmdate
Gets the current time after the difference with GMT.
Syntax: string gmdate (string format, int timestamp);
return value: String
Function Type: time date
Content description This function is similar to the date () function, and this function returns the time after the GMT (Greenwich Mean Time, GMT) difference

Usage examples
echo Date ("M D y h:i:s", Mktime (0,0,0,1,1,1998));
Echo gmdate ("M D y h:i:s", Mktime (0,0,0,1,1,1998));
?>
If the machine executing this example is in Finland (Finland, GMT +0200), the result returned is:
01 1998 00:00:00
Dec 31 1997 22:00:00
Reference date () Mktime () Gmmktime ()

Easter_date
Calculates the Easter date.
Syntax: int easter_date (int [year]);
return value: Integer
Function Type: time date
Content Description
Enter a year that returns the Easter date of the year in the form of a Unix timestamp, and calculates the date of the current day if no year is entered. The value is noted that the entered year must be between 1970-2037 and cannot be calculated.
Usage examples
echo Date ("M-d-y", Easter_date (1999));
echo Date ("M-d-y", Easter_date (2000));
echo Date ("M-d-y", Easter_date (2001));
?>
Returns the result to
apr-04-1999
apr-23-2000
apr-15-2001

Easter_days
Calculates the number of dates between Easter and March 21.
Syntax: int easter_days (int [year]);
return value: Integer
Function Type: time date
Content Description Enter a year to calculate the number of dates between Easter and March 21 of the year and, if no year is entered, in the current year. This function can be used to replace the easter_date () 1970-2037 years beyond the scope of the calculation of the problem.
Usage examples
Echo Easter_days (1999);
echo easter_days (1492);
Echo Easter_days (1913);
?>
The result returned is:
14 (4/4)
32 (4/22)
2 (3/23)
Reference Easter_date ()

Mktime
Gets the Unix time stamp.
Syntax: int mktime (int hour, int minute, int second, int month, int day, int year);
return value: Integer
Function Type: time date
Content Description
Enter a time that returns a long integer for the Unix time stamp.
Usage examples
echo Date ("M-d-y", Mktime (0,0,0,12,32,1997));
echo Date ("M-d-y", Mktime (0,0,0,13,1,1997));
echo Date ("M-d-y", Mktime (0,0,0,1,1,1998));
?>
Reference date () time ()

Gmmktime
Get the Unix time stamp GMT.
Syntax: int gmmktime (int hour, int minute, int second, int month, int day, int year);
return value: Integer
Function Type: time date
Content Description Enter a time that returns the long integer of the unix GMT stamp.

Time
Gets the Unix time stamp for the current time.
Syntax: int time (void);
return value: Integer
Function Type: time date
The content description returns the stamp value for the current time.

Reference date ()

Microtime
Gets the one out of 10,000-second value of the Unix time stamp for the current time.
Syntax: string microtime (void);
return value: String
Function Type: time date
The content description returns the one out of 10,000-second stamp value of the current time. This function is also invalid if the operating system does not provide a gettimeofday () call function.

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.