轉自:http://www.cnblogs.com/jiu0821/p/5999566.html
Debian的時區配置
一. 修改時區
1. 查看當前時區
命令 : "date -R"
2. 修改設置Linux服務器時區
方法 A
命令 : "tzselect"
方法 B 僅限於RedHat Linux 和 CentOS
命令 : "timeconfig"
方法 C 適用於Debian
命令 : "dpkg-reconfigure tzdata"
3. 通過/etc/profile來修改
echo "export TZ='UTC'" >> /etc/profile
source /etc/profile
4. 復制相應的時區文件,替換系統時區文件;或者創建鏈接文件
cp /usr/share/zoneinfo/主時區/主時區/次時區 /etc/localtime
例如:在設置中國時區使用亞洲/上海(+8)
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或者
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ln -sf /usr/share/zoneinfo/UTC /etc/localtime 設置為UTC時間
二、查看和修改Linux的時間
1. 查看時間和日期
命令 : "date"
2.設置時間和日期
例如:將系統日期設定成2009年11月3日的命令
命令 : "date -s 11/03/2009"
將系統時間設定成下午5點55分55秒的命令
命令 : "date -s 17:55:55"
3. 將當前時間和日期寫入BIOS,避免重啟后失效
命令 : "hwclock -w"
注:
date
不加參數可以直接看到當前日期時間
cal
不加參數可以直接看到本月月歷
轉自:http://www.cnblogs.com/ibgo/p/5959610.html
NTP和RTC時間同步
以上方法似乎不奏效,后來發現Debian 從 jessie 開始使用systemd來管理任務。
$ timedatectl set-ntp true
再看狀態:
$ timedatectl status Local time: 五 2016-10-21 01:36:57 CST Universal time: 四 2016-10-20 17:36:57 UTC RTC time: 四 2016-10-20 17:36:58 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: no RTC in local TZ: no DST active: n/a
打開 /etc/systemd/timesyncd.conf:
# # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # See timesyncd.conf(5) for details [Time] #Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
加入時間更新服務器:
# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # See timesyncd.conf(5) for details [Time] #Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org Servers=ntp.ubuntu.com
這樣每次開機就會從ntp.ubuntu.com自動更新時間了。
參見:How to manage system services on Debian Jessie
https://blog.sleeplessbeastie.eu/2015/04/27/how-to-manage-system-services-on-debian-jessie/
查看硬件時間
# hwclock
把硬件的時間寫到操作系統(如果hwclock是昨天,則此命令會把系統當前的時間改到昨天):
# hwclock --hctosys
把系統當前的時間寫到硬件時鍾(寫到BIOS ?):這才是我們需要的
# hwclock --systohc