<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Admon Home &#187; hwclock</title>
	<atom:link href="http://www.admon.org/tag/hwclock/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.admon.org</link>
	<description>Linux System Administration</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:24:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Set timezone date and time in Linux</title>
		<link>http://www.admon.org/set-timezone-date-and-time-in-linux/</link>
		<comments>http://www.admon.org/set-timezone-date-and-time-in-linux/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 03:07:53 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[System Tuning]]></category>
		<category><![CDATA[hwclock]]></category>
		<category><![CDATA[redhat]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[timezone]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=491</guid>
		<description><![CDATA[Your computer has two timepieces; a battery-backed one that is always running (a.k.a. the hardware, BIOS, or CMOS clock), and another that is maintained by the operating system currently running, it&#8217;s called system clock. This document explains how to set your system clock, your timezone, and other stuff related to how linux does its time-keeping. [...]]]></description>
			<content:encoded><![CDATA[<p>Your computer has two timepieces; a battery-backed one that is always running (a.k.a. the hardware, BIOS, or CMOS clock), and another that is maintained by the operating system currently running, it&#8217;s called system clock. This document explains how to set your system clock, your timezone, and other stuff related to how linux does its time-keeping.<span id="more-491"></span></p>
<p>The hardware clock is generally only used to set the system clock when your operating system boots, and then from that point until you reboot or turn off your system, the system clock is the one used to keep track of time.</p>
<p>On Linux systems, you have a choice of keeping the hardware clock in <a href="http://geography.about.com/od/timeandtimezones/a/gmtutc.htm">UTC/GMT</a> time or local time. The preferred option is to keep it in UTC. The disadvantage with keeping the hardware clock in UTC is that if you dual boot with an operating system (like DOS) that expects the hardware clock to be set to local time, the time might be wrong in that OS.</p>
<p><strong>Set your timezone</strong></p>
<p>The timezone under Linux is set by a symbolic link from <em>/etc/localtime</em> to a file in the <em>/usr/share/zoneinfo</em> directory that corresponds with what timezone you are in. For example, since I&#8217;m of same timezone as Hong Kong, /etc/localtime is a symlink to <em>/usr/share/zoneinfo/Asia/Hong_Kong</em>. To set this up, run:</p>
<pre>[admon@planet ~]# ls -F /usr/share/zoneinfo/
Africa/      CST6CDT  Etc/     Greenwich  Kwajalein  Navajo     SystemV/   iso3166.tab
America/     Canada/  Europe/  HST        Libya      PRC        Turkey     posix/
Antarctica/  Chile/   Factory  Hongkong   MET        PST8PDT    UCT        posixrules
Arctic/      Cuba     GB       Iceland    MST        Pacific/   US/        right/
Asia/        EET      GB-Eire  Indian/    MST7MDT    Poland     UTC        zone.tab
Atlantic/    EST      GMT      Iran       Mexico/    Portugal   Universal
Australia/   EST5EDT  GMT+0    Israel     Mideast/   ROC        W-SU
Brazil/      Egypt    GMT-0    Jamaica    NZ         ROK        WET
CET          Eire     GMT0     Japan      NZ-CHAT    Singapore  Zulu

[admon@planet ~]# ln -sf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime</pre>
<p>Replace your timezone with something like <em>US/Pacific</em> or <em>Europe/Paris</em>. Have a look in the directories under <em>/usr/share/zoneinfo</em> to see what timezones meet your needs.</p>
<p>This assumes that you are running Red Hat (or Redhat  based Linux) . On older systems, you&#8217;ll find that <em>/usr/lib/zoneinfo</em> is used instead of <em>/usr/share/zoneinfo</em>.</p>
<p><strong>Set the system clock</strong></p>
<p>To set the system clock under Linux, use the date command. As an example, to set the current time and date to <em>Sun Dec 13 10:02:00 AM CST 2009</em>, type <em>date 12131002</em> (note that the time is in 24 hour notation).</p>
<pre>[admon@planet ~]# date
Sun Dec 13 10:09:29 CST 2009
[admon@planet ~]# date 12131002
Sun Dec 13 10:02:00 CST 2009</pre>
<p>You can reset system time without date information like this:</p>
<pre>[admon@planet ~]# date -s 10:04
Sun Dec 13 10:04:00 CST 2009</pre>
<p>If you wanted to change the year as well, just type <em>date 121310022009</em>. To set the seconds as well, type <em>date 12131002.30</em> or <em>date 121310022009.30</em>. The following line is an example. When the command runs succesfully, it returns current system time:</p>
<pre>[admon@planet ~]# date 121310212009.30
Sun Dec 13 10:21:30 CST 2009</pre>
<p>An alternative way is to load system date and time from BIOS like this:</p>
<pre>[admon@planet ~]# date
Sun Dec 13 10:02:04 CST 2009
[admon@planet ~]# hwclock --hctosys
[admon@planet ~]# date
Sun Dec 13 10:09:29 CST 2009</pre>
<p><strong>Set the hardware clock</strong></p>
<p>When Linux boots, A initialization script will run the <em>/sbin/hwclock</em> program to copy the current hardware clock time to the system. To set the hardware clock, a common way is to set the system clock first, and then sync the new system time to hardware clock by typing <em>/sbin/hwclock &#8211;systohc</em> (or <em>/sbin/hwclock &#8211;systohc &#8211;utc</em> if you are keeping the hardware clock in UTC).</p>
<pre>[admon@planet ~]# date
Sun Dec 13 10:29:57 CST 2009
[admon@planet ~]# hwclock --systohc
[admon@planet ~]# hwclock
Sun Dec 13 10:30:13 2009  -0.716300 seconds
[admon@planet ~]# date
Sun Dec 13 10:30:13 CST 2009</pre>
<p><strong>Sync local time with a time server</strong><br />
This can be done by an entry in root&#8217;s crontab like this:</p>
<pre>[admon@planet ~]# crontab -l
MAILTO=""
30 4,16 * * * (/usr/sbin/ntpdate -s clock.redhat.com time.nist.gov ntp.admon.org)</pre>
<p>It means your system time will be synced with these time servers every 12 hours. If you have a cluster of machines which must share the same time, it&#8217;s suggested to build your own time server, and get other servers synchronized with it.</p>
<p>Instead of keeping your system time up-to-date with the world, a local time server can be configed to supply delayed time, that means you can keep your system time delayed with the public. It&#8217;s helpful for some specific environment, like if you need some delayed <a href="http://planet.admon.org/howto/tips-for-rebuilding-mysql-replication/">mysql replication servers</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/set-timezone-date-and-time-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

