PHP obtains the current time (year, month, day, hour, minute, second)

Source: Internet
Author: User
PHP obtains the current time (year, month, day, hour, minute, second) 1 echodate (& amp; quot; h: I & amp; quot;); date (PHP3, PHP4) date-format a local time/date description stringdate (stringform... PHP obtains the current time (year, month, day, hour, minute, second)
1 echo date ("h: I ");
Date
(PHP 3, PHP 4)
Date-format a local time/date
Description
String date (string format [, int timestamp])
Returns the string generated by the integer timestamp according to the given format string. If no timestamp is provided, the current local time is used.
Note: the valid timestamp typically ranges from 20:45:54, January 1, December 13, 1901 to 03:14:07, January 1, January 19, 2038, Greenwich Mean Time. (The value range is the minimum and maximum values of 32-bit signed integers ). In Windows, the range is from January 1-20, 1970 to January 19.
To convert the time expressed by a string to a timestamp, use strtotime (). In addition, some functions in some databases convert their time formats to timestamps (for example, the UNIX_TIMESTAMP function of MySQL ).
The format string can recognize the following characters:
A-"am" or "pm"
A-"AM" or "PM"
B-Swatch Internet Time (see http://swatch.com/alu_beat/fs_itime.html)
D-the day of the month, which has two digits leading to zero, for example, "01" to "31"
D-the day of the week. The text represents three letters, for example, "Fri"
F-month, complete text format, such as "January"
G-hour, 12-hour format, no leading zero, for example, "1" to "12"
G-hour, 24-hour format, no leading zero, for example, "0" to "23"
H-hour, 12-hour format, for example, "01" to "12"
H-Hour, in 24-hour format, for example, "00" to "23"
I-minutes, for example, "00" to "59"
I (an uppercase letter of "I")-if it is a token, it is "1"; otherwise, it is "0"
J-the day in the month, without leading zero, for example, "1" to "31"
L (lowercase letter of "L")-day of the week, complete text format, such as "Friday"
L-Boolean value indicates whether it is a leap year, for example, "0" or "1"
M-month, for example, "01" to "12"
M-month, represented in text, with three letters, for example, "Jan"
N-month, without leading zero, for example, "1" to "12"
O-hours different from Greenwich Mean Time, for example, "+ 0200"
Date in the format of r-RFC 822, such as "Thu, 21 Dec 2000 16:01:07 + 0200" (added in PHP 4.0.4)
S-seconds, for example, "00" to "59"
S-English suffix after the number of days per month, 2 characters, such as "st", "nd", "rd" or "th"
T-the number of days in a given month, for example, "28" to "31"
T-the Time zone of the local machine, such as "EST" or "MDT" ([note]). in Windows, it is in full text format, such as "Eastern Standard Time ", the Chinese version displays "China Standard Time ".)
U-number of seconds since Unix epoch (January 1 1970 00:00:00 GMT)
The day of the week, represented by a number, for example, "0" (Sunday) to "6" (Saturday)
Week of the year in W-ISO-8601 format, starting from Monday each week (newly added in PHP 4.1.0)
Y-year, four digits, such as "1999"
Y-annual fee, two digits, for example, "99"
The day of the z-year, for example, "0" to "365"
The number of seconds of the Z-time difference offset (for example, "-43200" to "43200"). The time zone offset to the west of UTC is always negative, and the time zone offset to the east of UTC is always positive.
Unrecognized characters in the format string are displayed as is. When gmdate () is used, "0" is always returned ".
Example 1. date ()
12 echo date ("l dS of f y h: I: s A"); echo "Maid 1, 2000 is on ". date ("l", mktime ));
Escape by adding a backslash before the character in the format string to avoid it being interpreted according to the preceding table. If the character after the backslash is itself a special sequence, escape the backslash. Example 2. escape characters in date ()
Echo date ("l \ t \ h \ e jS"); // Display is similar to: Saturday the 8th
Date () and mktime () can be used together to obtain the future or past date. Example 3. date () and mktime ()
123 $ tomorrow = mktime (0, 0, 0, date ("m"), date ("d") + 1, date ("Y ")); $ lastmonth = mktime (, 0, date ("m")-1, date ("d"), date ("Y"); $ nextyear = mktime, 0, date ("m"), date ("d"), date ("Y") + 1 );
Note: Due to the timeout, this method is more reliable than simply adding or subtracting one day or one month on the timestamp.
Some examples of formatting a date using date. Note that you need to escape all other characters, because at present, characters with special meanings will produce unwanted results, and other characters may be used in future PHP versions. When escaping, use single quotes to avoid conversion of characters similar to \ n into line breaks. Example 4. date () Formatting
12345678910/* Today is March 10th, 2001, 5:16:18 */$ today = date ("F j, Y, g: I a"); // March 10,200 1, 5: 16 pm $ today = date ("m. d. y "); // 03.10.01 $ today = date (" j, n, Y "); /// 10, 3, 2001 $ today = date (" Ymd "); // 20010310 $ today = date ('H-I-s, j-m-y, it is w Day Z'); // 05-16-17, 10-03-01,163 1 1618 6 Fripm01 $ today = date ('\ I \ t \ I \ s \ t \ h \ e jS \ d \ a \ y. '); // It is the 10th day. $ today = date ("d m j G: I: s T Y"); // Sat Mar 10 15:16:08 MST 2001 $ today = date ('H: m: s \ m \ I \ s \ m \ o \ n \ t \ h '); // 17:03:17 m is month $ today = date ("H: I: s "); // 17:16:17
To format dates in other languages, use the setlocale () and strftime () functions.
See getlastmod (), gmdate (), mktime (), strftime (), and time ().

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.