PHP temporal function time (), date (), mktime () difference

Source: Internet
Author: User
Tags month name time and date

PHP temporal function time (), date (), mktime () Differences Browse: 1161 Release Date: 2014/12/18 Category: System code keyword: PHP time function timing () date () mktime () php temporal function time (), date ( ), Mktime () difference
Php:time (), date (), Mktime () Day and time function library {often forgotten}

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.
Example one of the use examples:
  1. <?  
  2.          print (date (  &NBSP;
  3. Print("July 1, is on a" . Date("L", mktime(0,0,0,7,1,2000 )));  < /c4>
  4. ?>
Copy code example two:
  1. <?  
  2.          $tomorrow   = mktime (0,< Span class= "lit" >0,0,date ( "M" )  date ( "D" 1 ,date ( "Y"
  3.          $lastmonth   = mktime (0,< Span class= "lit" >0,0,date ( "M" 1date ( "D"  date "Y"
  4. $nextyear = mktime(0,0,0,date("M"), date(" D ", date(" Y ") +1);
  5. ?>
Copy Code 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
  1. <? PHP
  2. setlocale ("Lc_time", "C");
  3. Print(strftime("%A in Finnish is");
  4. setlocale ("Lc_time", "fi");
  5. Print(strftime("%A, in French"));
  6. setlocale ("Lc_time", "fr");
  7. Print(strftime("%A and in German"));
  8. setlocale ("Lc_time", "de");
  9. Print(strftime("%A.N"));
  10. ?>
Copy code reprint original address: http://www.jb100.net/html/content-22-942-1.html

PHP temporal function time (), date (), mktime () difference

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.