Php:time (), date (), Mktime ()

Source: Internet
Author: User
Tags current time month name string format time and date

Date and time function library {often forget}
Checkdate: Verify the correctness of the date.
Date: Formats the time of the server.
Strftime: Formats the server's time locally.
GETDATE: Get time and date information.
Gettimeofday: Get the current time.
Gmdate: Get 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: Get UNIX time stamp.
Gmmktime: Get UNIX time stamp GMT.
Time: Gets the UNIX timestamp 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 formats the server's time.
Syntax: string date (string format, int [timestamp]);
return value: String
Function Type: time date
The? string for the return value of the content description is determined by the configured 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 dates to other language languages, you should use the setlocale () 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"
H-24 hours of 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 of hours, less than two 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.
Use 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 formats the server's time 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 changes depending on the local language configuration setlocale ().
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 A 12-hour number is used to indicate the number of hours (ranging from 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
<?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"));
?>

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.