Solutions to date time difference in PHP

Source: Internet
Author: User
Tags iso 8601 iso 8601 format
The date (Y-m-dH: I: s) is not the same as the actual time. So I found the relevant information and found out the reason. Cause of this phenomenon: php 5.1.0 and later versions. date is added to ini. timezone is disabled by default... "/> <scripttype =" text/javascript "today, the date (" Y-m-d H: I: s ") is always the same as the actual time. So I found the relevant information and found out the reason. Cause of this phenomenon: from php5.1.0, the date. timezone option is added to php. ini, which is disabled by default, that is, the displayed time zone. By default, the Greenwich mean time and our time (Beijing time) are exactly eight hours different. Solution: 1. the simplest method is not to use php5.1 or a later version. 2. modify php. the ini configuration file can be found in php. search for date in ini. timezone and modify. php in Windows. ini is generally in: C:/WINDOWS/php. php in ini Linux. ini is generally in:/etc/php. follow the prompts above to find php. date. this line of timezone can be added if it cannot be found. Remove the semicolon and change it to date. timezone = "Asia/Shanghai". remember to restart the http service (such as apache2 or iis. Date. for the values following the timezone semicolon, the available values in mainland China are: 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) and Singapore: Asia/Singapore foreigners seem to have missed other available values in Beijing: etc/GMT-8, Singapore, Hongkong, PRC is what? PRC is from the People's Republic of China. 3. if you must use php5.1 or a later version, you cannot modify the php. ini configuration file. (1) add 8 hours to the PHP code processing time to get the correct China time date ('Y-m-d H: I: S', time () + 8*3600 ); (2) add date_default_timezone_set (XXX) to the time initialization statement, or use date_default_timezone_set (XXX) in the page header) set my default time zone to date_default_timezone_set ('Asia/Shanghai. The format string can recognize the following format parameter string format characters, indicating the number of the day in the example of the return value--d month, and the number of the day in the week from the 2nd digit of the leading zero to the 31D, text indicates the day of the day from the three letters Mon to Sunj, without the day of the week leading to Zero 1 to 31l (lowercase letters of "L, complete text format Sunday to SaturdayN ISO-8601 format number represents the day of the week (PHP 5.1.0 plus) 1 (represents Monday) to 7 (represents Sunday) S the English suffix after the day of each month, 2 characters including st, nd, rd, or th. It can be the day of the week w with j. The number represents 0 (Sunday) to 6 (Saturday) the day of the year z 0 to 365 weeks--the week of the year W ISO-8601 format, starting from Monday every week (new PHP 4.1.0) for example: 42 (42nd weeks of the year) month--F month, in the complete text format, such as month represented by January or March January to Decemberm, the month is represented by the month Jan to Decn numbers with the leading 0-01 to 12 M abbreviations, there is no leading zero 1 to 12 t given the number of days for the month 28 to 31 years--L is a leap year if it is a leap year is 1, otherwise it is a 0o ISO-8601 format year number. This is the same as Y, except that the week number (W) of ISO belongs to the previous year or the next year. (New PHP 5.1.0) Examples: 1999 or 2003Y 4-digit full representation of the year for example: 1999 or 2003y 2-digit representation of the year for example: 99 or 03 time-a lowercase morning and afternoon values am or pmA Capital morning and afternoon values AM or PMB Swatch Internet standard values 000 to 999g hours, 12 hours format, no leading 0-1-12G hours, 24-hour format, no leading 0-23 h, 12-hour format, with leading 0-01-12 H, 24-hour format, there is a number of minutes from to 23i with a leading zero, 00 to 59> s, and a leading zero to 59> time zone--e time zone identifier (new in PHP 5.1.0), for example: UTC, GMT, whether the value of Atlanta/AzoresI is 1 if the value of GMT is GMT; otherwise, the number of hours with a difference between 0O and Greenwich Mean Time is + 020. The difference between 0 P and Greenwich Mean Time (GMT). the hour and minute are separated by a colon (new in PHP 5.1.3), for example: + 02: 00 T the time zone of the local machine, for example: EST, MDT ([translator's note] in Windows, it is in full text format, for example, "Eastern Standard Time", and the Chinese version displays "Chinese Standard Time "). The number of seconds of the Z time difference offset. 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. -43200 to 43200 complete date/time--c ISO 8601 format date (new PHP 5): 19: 21 + 00: 00r RFC 822 format date such as: Thu, 21 Dec 2000 16:01:07 + 0200U the number of seconds since the Unix epoch (January 1 1970 00:00:00 GMT). For details, see time () classification: PHP
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.