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

Source: Internet
Author: User
Tags echo date uppercase letter
PHP Gets the current time (year, month, day, hour, minute, second)
1echo date ("h:i");
Date
(PHP 3, PHP 4)
date-formatting a local time/date
Description
String date (string format [, int timestamp])
Returns a string that is the result of the timestamp of an integer in a given format string. If no timestamp is given, the local current time is used.
Note: A valid timestamp typically ranges from GMT December 13, 1901 20:45:54 to January 19, 2038 03:14:07. (This range conforms to the minimum and maximum values of a 32-bit signed integer). This range is limited in Windows systems from January 1, 1970 to January 19, 2038.
To convert the time that a string is expressed to a timestamp, you should use Strtotime (). In addition some databases have some functions to convert their time format into timestamps (such as 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 ("translator's note" See http://swatch.com/alu_beat/fs_itime.html)
The day ordinal of a D – month with a leading zero 2-digit number, such as "31"
D – Day of the week, text representation, 3 letters, e.g. "Fri"
F – month, full text format, e.g. "January"
G – hours, 12-hour format, no leading zeros, such as "1" to "12"
G – hours, 24-hour format, no leading zeros, such as "0" to "23"
H – hours, 12-hour format, e.g. "01" to "12"
H – hours, 24-hour format, e.g. "00" to "23"
I – minutes, e.g. "00" to "59"
I (Uppercase letter of "I")-if daylight saving time is "1", otherwise "0"
J – the Day of the month without leading zeros, such as "1" to "31"
L (Lowercase letter of "L")-day of the week, full text format, e.g. "Friday"
L – Boolean value indicates whether it is a leap year, such as "0" or "1"
M – month, e.g. "12"
M – Month, text representation, 3 letters, e.g. "Jan"
N – month, no leading zeros, such as "1" to "12"
O-hours, such as "+0200", that differ from Greenwich mean
R–RFC 822 format date, e.g. "Thu, Dec 16:01:07 +0200" (PHP 4.0.4 New)
S-number of seconds, e.g. "00" to "59"
S-suffix, 2 characters, such as "St", "nd", "rd" or "th", after the number of days per month
T-the number of days that a given month should have, such as "28" through "31"
T-the local time zone, such as "EST" or "MDT" (the "translator note" is in full text format under Windows, such as "Eastern Standard Time", the Chinese version will show "Chinese standards times".) )
U the number of seconds since the Unix era (January 1 1970 00:00:00 GMT) started
W – Day of the week, numbers indicated, e.g. "0" (Sunday) to "6" (Saturday)
Week of the w–iso-8601 format year, starting from Monday (PHP 4.1.0 New)
Y – Year, 4 digits, for example "1999"
Y – Annual fee, 2 digits, e.g. "99"
The day of the Z – year, such as "0" to "365"
Z – The number of seconds (for example, "43200" to "43200") of the time difference offset. The time zone offset in the west of UTC is always negative, and the time zone offset to the east of UTC is always positive.
Characters that are not recognized in the format string are displayed as-is. The "Z" format always returns "0" when using Gmdate ().
Example 1. Date () example
12echo Date ("L DS of F Y h:i:s a"), echo "July 1," on A ". Date ("L", Mktime (0,0,0,7,1,2000));
Escaping a character in a format string preceded by a backslash prevents it from being interpreted as described in the preceding table. If the character after the backslash is a special sequence, it also escapes the backslash. Example 2. In the date () transit literal character
echo Date ("L \\t\h\e JS"); displaying similar to: Saturday the 8th
You can use Date () and mktime () together to get a date in the future or past. Example 3. Date () and mktime () examples
123$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);
Note: Due to daylight saving time, this method is more reliable than simply adding a day or one-month seconds to the timestamp.
Some examples of using date () to format dates. Note that all other characters are escaped, because characters with special meanings now produce unwanted results, and the remaining characters may be used in future versions of PHP. When escaping, note that single quotation marks are used to avoid characters like \ n being changed into line breaks. Example 4. Date () formatting
12345678910/* Today is March 10th, 2001, 5:16:18 pm */$today = Date ("F J, Y, g:i a"); March, 2001, 5:16 pm$today = Date ("M.d.y"); 03.10.01$today = Date ("J, N, Y"); Ten, 3, 2001$today = Date ("Ymd"); 20010310$today = Date (' H-i-s, J-m-y, it's W day Z '); 05-16-17, 10-03-01, 1631 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 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 for other languages, you should use the setlocale () and strftime () functions.
See Getlastmod (), Gmdate (), Mktime (), strftime (), and time ().
  • 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.