After installing the Windows 7 and centos6.0 systems for a while, there has always been a small problem, that is, the system time of the two is always different, with a difference of 8 hours, in linux, the system time is always 8 hours earlier than in windows. that is to say, when windows is six o'clock P.M. in the morning, it is in linux. After I set the system time in windows correctly
Windows 7 andCentos6.0 dual systems have been around for a while, and there is always a small problem, that is, the system time of the two is always different, with a difference of 8 hours, in linux, the system time is always 8 hours earlier than in windows. that is to say, when windows is six o'clock P.M. in the morning, it is in linux. After I set the system time in windows correctly, the time in linux is incorrect. if I set the time in linux correctly, windows is incorrect. I think it is a small problem, and I don't care about it.
Recently I was studying php. today I wrote a testing program for printing the system time. I found that the printing time is incorrect, which is 8 hours different from the currently displayed system time (note, I set up a php environment in windows), but the difference is that the time is 8 hours later than the windows system time, at this time, I recalled the problem in linux. So I decided to study this issue.
I searched the internet for this problem and found that not only did I encounter it, but I got the following conclusion based on the explanations of the netizens. For the time inconsistency between centos and windows, it turns out that the system time is calculated differently. The computer has a BIOS time, that is, the CMOS time. windows uses the BIOS time as the system time, while centos uses the BIOS time as the UTC standard time by default, the system time is calculated based on the time zone settings. for example, if the current system time zone is set to Beijing (Zone 8 in the East ), then the system time will be added to the BIOS time for 8 hours, resulting in an error. At this time, if we set the system time in linux correctly, it will update the BIOS time (current time-8 hours) at the same time. The next time we start windows, in windows, the BIOS time is used as the system time. Speaking of this, we all know the solution, changing the time computing mode for windows or linux systems. I chose to modify the time calculation method for linux:
Shell> vim/etc/sysconfig/clock
Modify the file to the following format.
ZONE = "Asia/Shanghai" # set the time ZONE
UTC = false # disable the coordinated world time
ARC = false
: Wq! Save and exit
Shell> ntpdate pool.ntp.org # aligning time
Shell>/sbin/hwclock -- systohc # set the hardware time to be consistent with the system time and calibrate
This problem has been solved.
In addition, the problem in php is that the time zone is not specified in php. ini, and the code is not used in the page header.
Date_default_timezone_set () is used to set the time zone. The UTC standard time is used by default, which is 8 hours later than the current system.
In php. ini, you can set the time zone or use the function you just used to set the time zone.