Php Date and Time

Source: Internet
Author: User
Tags what php
? Phpecho $ showtimedate (Y-m-dH: I: s );? Displayed in the format of year-month-day hour: minute: Wonderful related time parameter:

? Php echo $ showtime = date (Y-m-d H: I: s );? Displayed in the format of year-month-day hour: minute: Wonderful related time parameter: a-am, pm A-AM, or PM d-days, two digits, if there are less than two digits, add the first zero. For example, 01 to 31 D to the day of the week, there are three English letters. For example, Fri F-month, full English name, for example, January h.


Display format: year-month-day hour: minute: Wonderful
Related time parameters:
A-"am" or "pm"
A-"AM" or "PM"
D-a few days, two digits. If there are less than two digits, fill in the first zero. For example, "01" to "31"
D-the day of the week, with three English letters, for example, "Fri"
F-month, full English name; for example: "January"
H-12 hours, for example, "01" to "12"
H-24 hours, for example, "00" to "23"
Hours in the g-12 hour format. Less than two hours do not fill in zero. For example: "1" to 12"
Hours in the G-24-hour format. Less than two hours do not fill in zero. For example: "0" to "23"
I-minutes; for example: "00" to "59"
J-a few days, two digits. If less than two digits are left blank, for example, "1" to "31"
L-the day of the week, full name in English; for example: "Friday"
M-month, two digits. If there are less than two digits, add zero in front, for example, "01" to "12"
N-month, two digits. If less than two digits are left blank, for example, "1" to "12"
M-month, with three English letters, for example, "Jan"
S-seconds; for example: "00" to "59"
The end of the S-character is followed by an English sequence, with two English letters, for example, "th", "nd"
T-specifies the number of days in a month, for example, "28" to "31"
U-total seconds
W-number of weeks, for example, "0" (Sunday) to "6" (Saturday)
Y-year, four digits, such as: "1999"
Y-year, two digits, for example, "99"

Z-the day of the year, for example, "0" to "365"


When PHP versions later than PHP5.3 are used, if it is time-related,

"PHP Warning: date () [function. date]: It is not safe to rely on the system's timezone settings. you are * required * to use the date. timezone setting or the date_default_timezone_set () function. in case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. we selected 'utc' for '8. 0/no DST 'Instead in"

In fact, when using functions such as date () in PHP 5.1.0, if the timezone settings are incorrect, the E_NOTICE or E_WARNING information will be generated each time the time function is called. In php5.1.0, date. the timezone option is disabled by default. No matter what php Command is used, the Greenwich Mean Time is used. However, it seems that this error will be forcibly thrown out in PHP5.3 if it is not set, to solve this problem, just localize it.

There are three methods (either of them ):

1. Use date_default_timezone_set () in the page header to set date_default_timezone_set ('prc'); // echo date ('Y-m-d H: I: s') in the East eight time zone ');

2. Use ini_set ('date. timezone ', 'Asia/Shanghai') in the page header ');

3. Modify php. ini. Open php5.ini to search for date. timezone. Remove the semicolon and change it to: date. timezone = PRC.

Restart the http service (such as apache2 or iis.

XXX can be any correct value. In China, the following values can be used: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (Chongqing, Shanghai, and Urumqi in sequence). Hong Kong and Taiwan regions are available: Asia/Macao, asia/Hong_Kong, Asia/Taipei (Macau, Hong Kong, and Taipei in sequence), Singapore: Asia/Singapore, and PRC.


Method for obtaining the date after 30 days:

The mktime () method is used:
Echo date ("Y-m-d", mktime (0, 0, 0, date ("m"), date ("d") + 30, date ("Y ")));

Use time:
Echo date ('Y-m-d', time () + (30*24*60*60 ));

Use srtotime:
Echo date ('Y-m-d', strtotime ('+ 30 Day ');

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.