PHP time (), date (), mktime () Difference Introduction _php Tutorial

Source: Internet
Author: User
Tags echo date local time month name time and date
Checkdate: Verify the correctness of the date.
Date: Formats 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 GMT difference.
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: The GMT time stamp for UNIX is obtained.
Time: Gets the UNIX timestamp for the current time.
Microtime: Gets the one out of 10,000-second value of the UNIX timestamp for the current time.

Checkdate Verify that the date is correct.

Syntax: int checkdate (int month, int day, int);
return value: Integer
Function type: Time and date
The content description returns True if the date is valid, or False if there is a problem with the date. This function can be used to check if a date is valid. The valid range is as follows:
The year is 0-32,767 years
Month is 1-12 months
The day changes with the month and leap year

Date formats the time of the server.

Syntax: string date (string format, int [timestamp]);
return value: String
Function type: Time and date
The content description returns the value of the? string is determined by the configured format. If there is an incoming timestamp value, the timestamp is formatted and returned if no time stamp value is passed, and the current server's time is formatted. To convert a date to another language family format, use setlocale () and strftime () two functions. The options for string formatting are as follows:
A-"AM" or "PM"
A-"AM" or "PM"
D-A few days, two digits, if less than two is the front 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"
H-12 hours of the hour; such as: "01" to "12"
H-hour of 24-hour system; such as: "00" to "23"
G-12 hours of the hour, less than two digits do not fill 0; such as: "1" to 12 "
G-24 hours of the hour, less than two does not fill 0; such as: "0" to "23"
I-minute; such as: "00" to "59"
J-A few days, two digits, if less than two bits do not fill 0; such as: "1" to "31"
L-Day of the week, English full name; such as: "Friday"
M-month, two digits, if less than two digits in front of 0; such as: "01" to "12"
N-month, two digits, if less than two digits does not fill 0; such as: "1" to "12"
M-month, three letters of English; such as: "Jan"
S-second; such as: "00" to "59"
S-End With English ordinal number, two English letters; such as: "th", "nd"
T-the number of days in the specified 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 a year; such as: "0" to "365"
Other characters that are not listed above directly list the character.

Using examples,

Example one:

Copy the Code code as follows:
Print (Date ("L DS of F Y h:i:s A"));
Print ("July 1, is on a". Date ("L", Mktime (0,0,0,7,1,2000)));
?>

Example two:

Copy the Code code as follows:
$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 to be formatted locally.
Syntax: string strftime (string format, int [timestamp]);
return value: String
Function type: Time and date
The string of the content description return value is determined by the configured format. If there is an incoming timestamp value, the timestamp is formatted and returned if no time stamp value is passed, and the current server's time is formatted locally. The month or week name varies with the local language configuration setlocale ().
The returned string can be in the following format:
%a 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.
The%c local end datetime is a better representation of the string.
%d numbers indicate the day ordinal of the month (range 00 to 31).
The%H uses a 24-hour number to denote the number of hours (ranging from 00 to 23).
%I A 12-hour number indicates the number of hours (range 01 to 12).
%j indicates the day of the Year in Numbers (range 001 to 366).
Number of%m months (range from 1 to 12).
%M minutes.
%p indicates the local time with ' AM ' or ' PM '.
%s Number of seconds.
The number of%u is expressed as the week of the current year, and the first one weeks start in Sunday.
The%W number is expressed as the week of the current year, and the first one weeks start in Monday.
%w numbers indicate the day of the week (0 is Sunday).
%x does not include date notation for time.
%x does not include a time representation of the date.
The%y two digits represent the year (range from 00 to 99).
%Y a full year number representation, that is, four digits.
%Z time zone or name abbreviation.
Percent% character.

Usage examples

copy code code is as follows:
!--? PHP 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"));
?

Reference setlocale () mktime ()
GetDate Get time and date information.
Syntax: array getdate (int timestamp);
return value: Array
Function type: Time and date
The content description returns an array of elements that include the following items:
"Seconds"-seconds
"Minutes"-min
"Hours"-when
"Mday"-the day ordinal of the month
"Wday"-the number of days of the week
"Mon"-month number
"Year"-years, number
"Yday"-the number of days of the year; such as: "299"
"Weekday"-the full name of the week; such as: "Friday"
"Month"-the full name of the month; such as: "January"
Gettimeofday get the current time.
Syntax: array gettimeofday (void);
return value: Array
Function type: Time and date
The content description returns an array of elements that include the following items:
"SEC"-sec
"USec"-one out of 10,000 seconds
"Minuteswest"-minutes of Greenwich Mean
"Dsttime"-the purpose of the time zone
The gmdate obtains the current time with the GMT difference.
Syntax: string gmdate (string format, int timestamp);
return value: String
Function type: Time and date
This function is similar to the date () function, and differs from the time that this function returns after Greenwich Mean Time (Greenwich Mean, GMT)

Usage examples

Copy the Code code as follows:
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:
Jan 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 and date
Content Description: Enter a year, the date of the year is returned in the format of the UNIX timestamp, and if no year is entered, the current year is calculated. Note that the input year must be between A.D. 1970-2037, otherwise it cannot be calculated.
Usage examples

Copy the Code code as follows:
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 as

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 and date
The content description enters a year to calculate the number of dates between Easter and March 21 in that year, and if no year is entered, the year is calculated. This function can be used instead of easter_date () 1970-2037 years outside the scope of the problem cannot be calculated.
Usage examples

Copy the Code code as follows:
Echo Easter_days (1999);
echo easter_days (1492);
Echo Easter_days (1913);
?>

The returned result 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 and date
Content Description: Enter a time that returns a long integer of the UNIX timestamp.
Usage examples

Copy the Code code as follows:
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 gets UNIX time-stamped GMT.

Syntax: int gmmktime (int hour, int minute, int second, int month, int day, int year);

return value: Integer

Function type: Time and date
Description: Enter a time that returns a long integer of UNIX's GMT-stamp.
Time to get the UNIX timestamp for the current time.
Syntax: int time (void);
return value: Integer
Function type: Time and 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 timestamp for the current time.
Syntax: string microtime (void);
return value: String
Function type: Time and date
The content description returns the one out of 10,000-second stamp value for the current time. This function is also invalid if the operating system does not provide a system call function for Gettimeofday ().

http://www.bkjia.com/PHPjc/313550.html www.bkjia.com true http://www.bkjia.com/PHPjc/313550.html techarticle checkdate: Verify the correctness of the date. Date: Formats the time of the server. Strftime: The time of the server is formatted locally. GETDATE: Get time and date information. ...

  • Related Article

    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.