centos
这个为准 时区改为北京时间
mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
同步定时为修改后时区时间
/bin/systemctl restart crond.service
service rsyslog restart
tail -f /var/log/cron
命令行 timedatectl set-timezone America/Fortaleza
vim ~/.profile 也输入同样命令
命令行 date 查看时间
php 配置文件/usr/local/php/etc/php.ini
[Date]下面
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/Fortaleza
mysql 配置文件/etc/my.cnf
[mysqld]下面
default-time_zone='-03:00'
如何修改CentOS服务器时间为北京时间
- CentOS系统,发现服务器时间与北京时间往往不一致,存在时差。
> date
1.可以执行tzselect
命令按提示更换时区,依次选择5-Asia,9-China,1-Beijing Time。
选 Asia, CentOS里序号5,aliyunOS里序号4
选 China,序号一般是 9
选 Beijing 序号1
选 Yes 序号 1
You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
后续步骤
1.将TZ='Asia/Shanghai'; export TZ这行添加到/etc/profile(所有用户生效)或者~/.bash_profile(当前用户生效)
2.退出重新登录即可,也可执行source /etc/profile或source ~/.bash_profile立即生效
3.这时候再执行date查看日期就可以发现时区改为北京时间啦。