Php:time (), date (), mktime () function difference

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags checkdate configuration content date date and time function library difference example function

Php:time (), date (), Mktime ()
Php:time (), date (), mktime () Date and time function library {often forgets}
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: 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 timestamp.
Gmmktime: GMT with UNIX time stamp.
Time: A UNIX timestamp that obtains the current time.
Microtime: The one out of 10,000-second value of the UNIX time stamp that obtained the current time.

The

Checkdate verifies the correctness of the date.
Syntax: int checkdate (int month, int day, int year);
return value: integer
Function kind: 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. Valid ranges are as follows:
year 0-32,767
Month 1-12 month
Day changes with month and leap year
date formats the server's time.
Syntax: string date (string format, int [timestamp]);
return Value: String
Function Kind: Time Date
Content Description The? string 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 dates to other language languages, you should use the setlocale () and strftime () two functions. The strings are formatted with the following options:
A-"AM" or "PM"
A-"AM" or "PM"
D-days, two digits, if less than two digits before 0; for example: "01" to "" "
D-Day of the week, three English letters; for example:" Fri "
F -month, full name in English; such as: "Whose"
h-12 hours; such as: "01" to "" "
H-24 hours of the hour, such as:" 00 "to" ""
g-12 hours, less than two digits do not fill 0; For example: "1" to "
G-24 Hours of the hour, less than two-digit 0; such as: "0" to "a"
I-minutes, such as: "00" to "a"
J-days, two digits, if less than two digits does not fill 0, such as: "1" to "" "
L-Day of the week, the full name of the English language, such as:" Friday "
M-month, two digits, if less than two digits 0 in front; such as: "01" to "the"
N-month, two digits, if less than two digits, do not make up 0, such as: "1" to "a"
M-month, three English letters, such as: "The first"
s-seconds, such as: "00" to "" "
S-word tailPlus English ordinal number, two English letters; such as: "th", "nd"
T-Specify the number of days of the month; such as: "28" to "" "
U-Total seconds
W-Number of days of the week, such as:" 0 "(Sunday) to" 6 "(Saturday)
Y-year, four digits; for example:" 1999 "
Y- years, two digits; such as: "" "
Z-the first day of the year, such as:" 0 "to" 365 "
other characters that are not listed directly list the character.
Use the example, example one:
.
Print (Date ("L DS of F Y h:i:s A"));
Print ("July 1,". 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);

The

Reference gmdate () mktime ()
strftime formats the server's time locally.
Syntax: string strftime (string format, int [timestamp]);
return Value: String
Function Type: Time Date
The string for the return value of the content description 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 in the following format:
%a the abbreviation for the day of the week.
%A The full name of the day of the week. An abbreviation for the
%b month name. The full name of the
%B month name. The
%c local end date time is better represented as a string.
%d is a number that represents the day of the month (range 00 to 31). The
%H uses a 24-hour number to indicate the number of hours (ranging from 00 to 23).
%I A 12-hour number is used to indicate the number of hours (ranging from 01 to 12). The
%j the number of days of the year (ranging from 001 to 366).
The number of people%m months (ranging from 1 to 12).
people%m minutes. The
%p indicates the local end time with ' AM ' or ' PM '.
%s seconds. The
%u number is expressed as the week ordinal of the current year, and the first one week begins in Sunday. The
%W number is expressed as the week ordinal of the current year, and the first one week begins in Monday. The
%w uses numbers to denote the day of the week (0 is Sunday).
%x does not contain a date representation of time. The
%x does not contain a time representation of dates. The
%y two digits indicates the year (range from 00 to 99). The
%Y the full year number, which is the four-digit number. The
%Z time zone or name abbreviation. The
% percent% character.
Use example
<?php
setlocale ("Lc_time", "C");
Print (Strftime ("%A in Finnish are");
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"));

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.