← 返回文章列表

Linux时间相关

设置时区

cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime

复制zoneinfo中相关地点或时区的文件,覆盖/etc/localtime,实现设置时区。

Ps:Chongqing,Shanghai均为北京时间。

同步网络时间

centos为例,安装ntp(Network Time Protocol,网络时间协议)

yum install ntp

使用ntpdate命令同步时间,需root权限

ntpdate time.nist.gov  

以下为一些常用网络时间域名

  • cn.pool.ntp.org
  • time.nist.gov
  • ……

格式化输出当前时间

mysql的样式:

date "+%Y-%m-%d %H:%M:%S"