This method is in the other people's posts to see, the original post here.
http://blog.csdn.net/change518/article/details/8448459
Thank the original author for helping me to solve the problem here.
Detailed steps are below, please see.
First, Reason
From php5.1.0 onwards, php.ini riga date.timezone This option, and is turned off by default
That is, the time displayed (whatever PHP command is used) is Greenwich Mean Time
And our Time (Beijing time) The difference is exactly 8 hours.
Ii. Solutions
method One : Add the following code before you get the time:
Date_default_timezone_set (PRC);
method Two : Change the php.ini inside the formulation, the specific operation is as follows:
Open php.ini Find Date.timezone Remove the preceding semicolon = after plus xxx (PRC), restart the HTTP service (such as Apache2 or IIS, etc.)
such as: DATE.TIMEZONE=PRC
For XXX, the values available in mainland China are: asia/chongqing, Asia/shanghai, Asia/urumqi, PRC (Chongqing, Shanghai, Urumqi, PRC)
Taiwan available: Asia/macao, Asia/hong_kong, Asia/taipei (Macau, Hong Kong, Taipei, respectively)
and Singapore: Asia/singapore
Others: Etc/gmt-8, Singapore, Hongkong
method Three : Echo Date ("Y-m-d h:i:s", Time () +8*60*60);
Example:
[PHP]View Plaincopy
- <?php
- //Show date and time of day
- Date_default_timezone_set (PRC);
- $date =Date ("y-m-d h:i:s");
- echo $date." <br> ";
- //Show yesterday's date and time
- $yesterday =Date ("y-m-d h:i:s", Time () -24*60*60);
- $y 1=date ("y-m-d h:i:s",mktime () -24*60*60);
- echo $yesterday." <br> ";
- echo $y 1." <br><br> ";
- $z =date ("z") +1; //Weekly basis: 0123456
- echo "Today is the first of 2010. " $z."Tian <br><br>";
- $z =date ("z") +5; //Weekly basis: 0123456 Friday, January 1 4+1=5
- $w =ceil ($z/7);
- echo "<br> today is the first of 2010. " $w."Zhou <br><br>";
- $time =time ();
- echo $time;
- ?>
Attached: Date time format
Date ("y-m-d h:i:s"); Format displayed: Year-month-day hours: minutes: seconds
Relevant time parameters:
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"
This is the end, because my is not I stir complex, so I use the first method, personally think the first method is relatively simple and good solution.
PHP uses date () to check out the current time 8 hours of resolution.