https://wiki.archlinux.org/api.php?action=feedcontributions&user=Tuxflo&feedformat=atomArchWiki - User contributions [en]2024-03-28T13:42:17ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=System_time&diff=227593System time2012-10-08T10:11:39Z<p>Tuxflo: /* Read clock */</p>
<hr />
<div>[[es:TIMEZONE]]<br />
[[fa:زمان]]<br />
[[fr:Horloge]]<br />
[[ru:Time]]<br />
[[zh-CN:Time]]<br />
[[Category:Mainboards and BIOS]] <!-- with regard to the hardware clock --><br />
[[Category:Daemons and system services]] <!-- as the basis/rationale for NTP --><br />
{{Article summary start}}<br />
{{Article summary text|This article provides an introduction to the concept of keeping time on computers in general, and describes how clocks are configured and managed in Arch Linux.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Network Time Protocol}}<br />
{{Article summary wiki|rc.conf}}<br />
{{Article summary end}}<br />
{{Out of date|Needs updating wrt https://wiki.archlinux.org/index.php/Rc.conf#New_configuration_file}}<br />
<br />
In an operating system the time (clock) is determined by four parts: Time value, Time standard, Time Zone, and DST ('''D'''aylight '''S'''aving '''T'''ime if applicable). This article explains what they are and how to read/set them. To ''maintain'' accurate system time on a network see [[Network Time Protocol]].<br />
<br />
== Hardware clock and system clock ==<br />
<br />
A computer has two clocks that need to be considered the "Hardware clock" and the "System/software clock": <br />
<br />
'''Hardware clock''' (a.k.a. the Real Time Clock (RTC) or CMOS clock) stores the values of: Year, Month, Day, Hour, Minute, and the Seconds. It does not have the ability to store the time standard (localtime or UTC), nor whether DST is used. <br />
<br />
'''System clock''' (a.k.a. the software clock) keeps track of: Time, Time Zone, and DST if applicable. It is calculated by the Linux kernel as the number of seconds since midnight January 1st 1970 UTC. The initial value of the system clock is calculated from the hardware clock, dependent on the value of the HARDWARECLOCK variable defined in {{ic|/etc/rc.conf}}. After boot-up has completed the system clock runs independently of the hardware clock. The Linux kernel keeps track of the system clock by counting timer interrupts.<br />
<br />
=== Read clock ===<br />
<br />
To check the current hardware clock time and system clock time respectively (the hardware clock time is presented in localtime even if the hardware clock set to UTC):<br />
<br />
# hwclock --show<br />
$ date<br />
<br />
=== Set clock ===<br />
<br />
To set the system clock directly:<br />
<br />
# date MMDDhhmmYYYY<br />
<br />
To set the hardware clock directly (the argument must be in local time, even if you keep your hardware clock in UTC.):<br />
# hwclock --set --date="YYYY-MM-DD hh:mm:ss"<br />
<br />
The hardware clock can be set from the system clock and vice versa:<br />
<br />
# hwclock --systohc<br />
# hwclock --hctosys<br />
<br />
=== hwclock daemon ===<br />
<br />
Standard behavior of most operating systems is:<br />
<br />
* Set the system clock from the hardware clock on boot<br />
* Keep accurate time of the system clock with an [[Network Time Protocol daemon|NTP]] daemon<br />
* Set the hardware clock from the system clock on shutdown. (On Arch Linux, the hardware clock is '''not''' set from system clock on shutdown. Although, it is adjusted for systematic drift with the --adjust flag).<br />
<br />
Arch Linux initscripts use '''hwclock''' to set the system clocks on boot, if {{ic|hwclock}} is in the [[daemon|daemons list]] in {{ic|/etc/rc.conf}} '''hwclock''' will also sync time on shutdown. Using the {{ic|hwclock}} daemon is not recommended if running the [[ntpd|NTP daemon]] as the NTP daemon adjusts the hardware clock, which may lead to {{ic|hwclock --adjust}} miscalculations.<br />
<br />
== Time standard ==<br />
<br />
There are two time standards: '''localtime''' and '''C'''oordinated '''U'''niversal '''T'''ime ('''UTC'''). The localtime standard is dependent on the current ''time zone'', while UTC is the ''global'' time standard and is independent of time zone values. Though conceptually different, UTC is also known as GMT.<br />
<br />
The standard used by hardware clock (CMOS clock, the time that appears in BIOS) is defined by operating system. By default, Windows uses localtime, Mac OS uses UTC, and UNIX-like operating systems vary. An OS that uses UTC standard, generally, will consider CMOS (hardware clock) time a UTC time (GMT, Greenwitch time) and make an adjustment to it while setting System time on boot according to your time zone. <br />
<br />
When using Linux it is beneficial to have the hardware clock set to the UTC standard and made known to all operating systems. Defining the hardware clock in Linux as UTC means that Daylight Savings Time will automatically be accounted for. If using the localtime standard the system clock will not be changed for DST occurrences assuming that another operating system will take care of the DST switch (and provided no NTP agent is operating).<br />
<br />
You can set the hardware clock time standard through the command line. You can check what you have set your Arch Linux install to use by:<br />
<br />
$ cat /etc/adjtime<br />
<br />
The hardware clock can be queried and set with the {{ic|hwclock}} command. To change the hardware clock time standard to localtime use:<br />
<br />
# hwclock -w --localtime<br />
<br />
And to set it to UTC use:<br />
<br />
# hwclock -w --utc<br />
<br />
These will generate {{ic|/etc/adjtime}} automatically, no further configuration is required.<br />
<br />
During kernel startup, at the point when the RTC driver is loaded, the system clock may be set from the hardware clock. Whether this occurs or not depends on the hardware platform, the version of the kernel and kernel build options. If this does occur, at this point in the boot sequence, the hardware clock time is assumed to be UTC and the value of {{ic|/proc/sys/class/rtcN/hctosys}} (N=0,1,2,..) will be set to 1. Later during execution of {{ic|/etc/rc.sysinit}}, the system clock is set again from the hardware clock dependent on the value of HARDWARECLOCK. Hence, having the hardware clock using localtime may cause some unexpected behavior during the boot sequence; e.g system time going backwards which is always a bad idea.<br />
<br />
=== UTC in Windows ===<br />
<br />
Using {{ic|regedit}}, add a {{ic|DWORD}} value with hexadecimal value {{ic|1}} to the registry:<br />
<br />
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal<br />
<br />
Alternatively, create a {{ic|*.reg}} file (on the desktop) with the following content and double click it to import it into registry:<br />
<br />
Windows Registry Editor Version 5.00<br />
<br />
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]<br />
"RealTimeIsUniversal"=dword:00000001<br />
<br />
Windows XP and Windows Vista SP1 have support for setting the time standard as UTC and can be activated in the same way. However, there is a bug after resuming from the suspend/hibernation state that resets the clock to ''localtime''. For these operating systems it is recommended to use ''localtime''.<br />
<br />
Should Windows ask to update the clock due to DST changes, let it. It will leave the clock in UTC as expected, only correcting the displayed time.<br />
<br />
The hardware clock and system clock time may need to be [[#Set clock|updated]] after setting this value.<br />
<br />
=== Common problems ===<br />
<br />
A common source of problems is that different programs that interact with the real time clock do not agree whether or not it should be in UTC or local time. This tends to manifest itself in the time being consistently off by the same number of hours as your time zone differs from UTC.<br />
<br />
This problem can usually be solved by only configuring the real time device in one location, by removing the HARDWARECLOCK line from {{ic|/etc/rc.conf}} and instead configuring this value in {{ic|/etc/adjtime}}. This is the default configuration location for the hwclock program, and initscripts will use this value if HARDWARECLOCK is not set in rc.conf.<br />
<br />
Once this is configured correctly, make sure that both system time and the real time clock are up-to-date before the next reboot.<br />
<br />
== Time Zone ==<br />
<br />
Be sure that {{ic|/etc/localtime}} is linked to the correct zone file. This is necessary not only for the localtime to be set correctly but also for other programs you may use. You can do this by:<br />
<br />
$ ls -l /etc/localtime<br />
<br />
You can find the time zones listed in {{ic|/usr/share/zoneinfo/}} and then you will need to find a major city that exists to your time zone. If you live in a specialized time zone area these will be listed in sub-directories.<br />
<br />
To change your time zone, link {{ic|/etc/localtime}} to the new zone file:<br />
<br />
# ln -sf /usr/share/zoneinfo/<Zone>/<SubZone> /etc/localtime<br />
<br />
Example:<br />
<br />
# ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime<br />
<br />
When you [[#Set clock|set the hardware clock]] the new time zone will be used; you can check your system's hardware clock within your BIOS.<br />
<br />
== Time Skew ==<br />
<br />
Every clock has a value that differs from ''real time'' (the best representation of which being [[Wikipedia:International Atomic Time|International Atomic Time]]), no clock is perfect. A quartz based electronic clock keeps imperfect time, but maintains a consistent inaccuracy. This base 'inaccuracy' is known as 'time skew' or 'time drift'. <br />
<br />
When the hardware clock is set with {{ic|hwclock}}, a new drift value is calculated in seconds per day. The drift value is calculated by using the difference between the new value set and the hardware clock value just before the set, taking into account the value of the previous drift value and the last time the hardware clock was set. The new drift value and the time when the clock was set is written to the file {{ic|/etc/adjtime}} overwriting the previous values. The hardware clock can be adjusted for drift when the command {{ic|hwclock --adjust}} is run; this occurs by default on shutdown if the {{ic|hwclock}} daemon is enabled. <br />
<br />
{{Note|If the hwclock has been set again less than 24 hours after a previous set, the drift is not recalculated as {{ic|hwclock}} considers the elapsed time period too short to accurately calculate the drift. It may be worth occasionally to stay in Linux so it gets calculated}}<br />
<br />
If the hardware clock keeps losing or gaining time in large increments, it is possible that an invalid drift has been recorded. This can happen if you have set the hardware clock time incorrectly or your [[#Time Standard|time standard]] is not synchronized with a Windows or Mac OS install. The drift value can be removed by removing the file {{ic|/etc/adjtime}}, then set the correct hardware clock and system clock time, and check if your [[#Time Standard|time standard]] is correct.<br />
<br />
The software clock is very accurate but like most clocks is not perfectly accurate and will drift as well. Though rarely, the system clock can lose accuracy if the kernel skips interrupts. There are some tools to improve software clock accuracy:<br />
* [[NTP]] can synchronize the software clock of a GNU/Linux system with internet time servers using the Network Time Protocol. NTP can also adjust the interrupt frequency and the number of ticks per second to decrease system clock drift.<br />
* {{AUR|adjtimex}} in [[Arch User Repository|AUR]] can adjust kernel time variables like interrupt frequency to help improve the system clock time drift.<br />
<br />
== Resources ==<br />
<br />
* [http://www.linuxsa.org.au/tips/time.html Linux Tips - Linux, Clocks, and Time]<br />
* [http://www.twinsun.com/tz/tz-link.htm Sources for Time Zone and Daylight Saving Time Data] for {{Pkg|tzdata}}<br />
* [http://www.ucolick.org/~sla/leapsecs/timescales.html Time Scales]<br />
* [[Wikipedia:Time]]</div>Tuxflohttps://wiki.archlinux.org/index.php?title=System_time&diff=227592System time2012-10-08T10:10:37Z<p>Tuxflo: /* Read clock */</p>
<hr />
<div>[[es:TIMEZONE]]<br />
[[fa:زمان]]<br />
[[fr:Horloge]]<br />
[[ru:Time]]<br />
[[zh-CN:Time]]<br />
[[Category:Mainboards and BIOS]] <!-- with regard to the hardware clock --><br />
[[Category:Daemons and system services]] <!-- as the basis/rationale for NTP --><br />
{{Article summary start}}<br />
{{Article summary text|This article provides an introduction to the concept of keeping time on computers in general, and describes how clocks are configured and managed in Arch Linux.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Network Time Protocol}}<br />
{{Article summary wiki|rc.conf}}<br />
{{Article summary end}}<br />
{{Out of date|Needs updating wrt https://wiki.archlinux.org/index.php/Rc.conf#New_configuration_file}}<br />
<br />
In an operating system the time (clock) is determined by four parts: Time value, Time standard, Time Zone, and DST ('''D'''aylight '''S'''aving '''T'''ime if applicable). This article explains what they are and how to read/set them. To ''maintain'' accurate system time on a network see [[Network Time Protocol]].<br />
<br />
== Hardware clock and system clock ==<br />
<br />
A computer has two clocks that need to be considered the "Hardware clock" and the "System/software clock": <br />
<br />
'''Hardware clock''' (a.k.a. the Real Time Clock (RTC) or CMOS clock) stores the values of: Year, Month, Day, Hour, Minute, and the Seconds. It does not have the ability to store the time standard (localtime or UTC), nor whether DST is used. <br />
<br />
'''System clock''' (a.k.a. the software clock) keeps track of: Time, Time Zone, and DST if applicable. It is calculated by the Linux kernel as the number of seconds since midnight January 1st 1970 UTC. The initial value of the system clock is calculated from the hardware clock, dependent on the value of the HARDWARECLOCK variable defined in {{ic|/etc/rc.conf}}. After boot-up has completed the system clock runs independently of the hardware clock. The Linux kernel keeps track of the system clock by counting timer interrupts.<br />
<br />
=== Read clock ===<br />
<br />
To check the current hardware clock time and system clock time respectively (the hardware clock time is presented in localtime even if the hardware clock set to UTC):<br />
<br />
# hwclock -r<br />
$ date<br />
<br />
=== Set clock ===<br />
<br />
To set the system clock directly:<br />
<br />
# date MMDDhhmmYYYY<br />
<br />
To set the hardware clock directly (the argument must be in local time, even if you keep your hardware clock in UTC.):<br />
# hwclock --set --date="YYYY-MM-DD hh:mm:ss"<br />
<br />
The hardware clock can be set from the system clock and vice versa:<br />
<br />
# hwclock --systohc<br />
# hwclock --hctosys<br />
<br />
=== hwclock daemon ===<br />
<br />
Standard behavior of most operating systems is:<br />
<br />
* Set the system clock from the hardware clock on boot<br />
* Keep accurate time of the system clock with an [[Network Time Protocol daemon|NTP]] daemon<br />
* Set the hardware clock from the system clock on shutdown. (On Arch Linux, the hardware clock is '''not''' set from system clock on shutdown. Although, it is adjusted for systematic drift with the --adjust flag).<br />
<br />
Arch Linux initscripts use '''hwclock''' to set the system clocks on boot, if {{ic|hwclock}} is in the [[daemon|daemons list]] in {{ic|/etc/rc.conf}} '''hwclock''' will also sync time on shutdown. Using the {{ic|hwclock}} daemon is not recommended if running the [[ntpd|NTP daemon]] as the NTP daemon adjusts the hardware clock, which may lead to {{ic|hwclock --adjust}} miscalculations.<br />
<br />
== Time standard ==<br />
<br />
There are two time standards: '''localtime''' and '''C'''oordinated '''U'''niversal '''T'''ime ('''UTC'''). The localtime standard is dependent on the current ''time zone'', while UTC is the ''global'' time standard and is independent of time zone values. Though conceptually different, UTC is also known as GMT.<br />
<br />
The standard used by hardware clock (CMOS clock, the time that appears in BIOS) is defined by operating system. By default, Windows uses localtime, Mac OS uses UTC, and UNIX-like operating systems vary. An OS that uses UTC standard, generally, will consider CMOS (hardware clock) time a UTC time (GMT, Greenwitch time) and make an adjustment to it while setting System time on boot according to your time zone. <br />
<br />
When using Linux it is beneficial to have the hardware clock set to the UTC standard and made known to all operating systems. Defining the hardware clock in Linux as UTC means that Daylight Savings Time will automatically be accounted for. If using the localtime standard the system clock will not be changed for DST occurrences assuming that another operating system will take care of the DST switch (and provided no NTP agent is operating).<br />
<br />
You can set the hardware clock time standard through the command line. You can check what you have set your Arch Linux install to use by:<br />
<br />
$ cat /etc/adjtime<br />
<br />
The hardware clock can be queried and set with the {{ic|hwclock}} command. To change the hardware clock time standard to localtime use:<br />
<br />
# hwclock -w --localtime<br />
<br />
And to set it to UTC use:<br />
<br />
# hwclock -w --utc<br />
<br />
These will generate {{ic|/etc/adjtime}} automatically, no further configuration is required.<br />
<br />
During kernel startup, at the point when the RTC driver is loaded, the system clock may be set from the hardware clock. Whether this occurs or not depends on the hardware platform, the version of the kernel and kernel build options. If this does occur, at this point in the boot sequence, the hardware clock time is assumed to be UTC and the value of {{ic|/proc/sys/class/rtcN/hctosys}} (N=0,1,2,..) will be set to 1. Later during execution of {{ic|/etc/rc.sysinit}}, the system clock is set again from the hardware clock dependent on the value of HARDWARECLOCK. Hence, having the hardware clock using localtime may cause some unexpected behavior during the boot sequence; e.g system time going backwards which is always a bad idea.<br />
<br />
=== UTC in Windows ===<br />
<br />
Using {{ic|regedit}}, add a {{ic|DWORD}} value with hexadecimal value {{ic|1}} to the registry:<br />
<br />
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal<br />
<br />
Alternatively, create a {{ic|*.reg}} file (on the desktop) with the following content and double click it to import it into registry:<br />
<br />
Windows Registry Editor Version 5.00<br />
<br />
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]<br />
"RealTimeIsUniversal"=dword:00000001<br />
<br />
Windows XP and Windows Vista SP1 have support for setting the time standard as UTC and can be activated in the same way. However, there is a bug after resuming from the suspend/hibernation state that resets the clock to ''localtime''. For these operating systems it is recommended to use ''localtime''.<br />
<br />
Should Windows ask to update the clock due to DST changes, let it. It will leave the clock in UTC as expected, only correcting the displayed time.<br />
<br />
The hardware clock and system clock time may need to be [[#Set clock|updated]] after setting this value.<br />
<br />
=== Common problems ===<br />
<br />
A common source of problems is that different programs that interact with the real time clock do not agree whether or not it should be in UTC or local time. This tends to manifest itself in the time being consistently off by the same number of hours as your time zone differs from UTC.<br />
<br />
This problem can usually be solved by only configuring the real time device in one location, by removing the HARDWARECLOCK line from {{ic|/etc/rc.conf}} and instead configuring this value in {{ic|/etc/adjtime}}. This is the default configuration location for the hwclock program, and initscripts will use this value if HARDWARECLOCK is not set in rc.conf.<br />
<br />
Once this is configured correctly, make sure that both system time and the real time clock are up-to-date before the next reboot.<br />
<br />
== Time Zone ==<br />
<br />
Be sure that {{ic|/etc/localtime}} is linked to the correct zone file. This is necessary not only for the localtime to be set correctly but also for other programs you may use. You can do this by:<br />
<br />
$ ls -l /etc/localtime<br />
<br />
You can find the time zones listed in {{ic|/usr/share/zoneinfo/}} and then you will need to find a major city that exists to your time zone. If you live in a specialized time zone area these will be listed in sub-directories.<br />
<br />
To change your time zone, link {{ic|/etc/localtime}} to the new zone file:<br />
<br />
# ln -sf /usr/share/zoneinfo/<Zone>/<SubZone> /etc/localtime<br />
<br />
Example:<br />
<br />
# ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime<br />
<br />
When you [[#Set clock|set the hardware clock]] the new time zone will be used; you can check your system's hardware clock within your BIOS.<br />
<br />
== Time Skew ==<br />
<br />
Every clock has a value that differs from ''real time'' (the best representation of which being [[Wikipedia:International Atomic Time|International Atomic Time]]), no clock is perfect. A quartz based electronic clock keeps imperfect time, but maintains a consistent inaccuracy. This base 'inaccuracy' is known as 'time skew' or 'time drift'. <br />
<br />
When the hardware clock is set with {{ic|hwclock}}, a new drift value is calculated in seconds per day. The drift value is calculated by using the difference between the new value set and the hardware clock value just before the set, taking into account the value of the previous drift value and the last time the hardware clock was set. The new drift value and the time when the clock was set is written to the file {{ic|/etc/adjtime}} overwriting the previous values. The hardware clock can be adjusted for drift when the command {{ic|hwclock --adjust}} is run; this occurs by default on shutdown if the {{ic|hwclock}} daemon is enabled. <br />
<br />
{{Note|If the hwclock has been set again less than 24 hours after a previous set, the drift is not recalculated as {{ic|hwclock}} considers the elapsed time period too short to accurately calculate the drift. It may be worth occasionally to stay in Linux so it gets calculated}}<br />
<br />
If the hardware clock keeps losing or gaining time in large increments, it is possible that an invalid drift has been recorded. This can happen if you have set the hardware clock time incorrectly or your [[#Time Standard|time standard]] is not synchronized with a Windows or Mac OS install. The drift value can be removed by removing the file {{ic|/etc/adjtime}}, then set the correct hardware clock and system clock time, and check if your [[#Time Standard|time standard]] is correct.<br />
<br />
The software clock is very accurate but like most clocks is not perfectly accurate and will drift as well. Though rarely, the system clock can lose accuracy if the kernel skips interrupts. There are some tools to improve software clock accuracy:<br />
* [[NTP]] can synchronize the software clock of a GNU/Linux system with internet time servers using the Network Time Protocol. NTP can also adjust the interrupt frequency and the number of ticks per second to decrease system clock drift.<br />
* {{AUR|adjtimex}} in [[Arch User Repository|AUR]] can adjust kernel time variables like interrupt frequency to help improve the system clock time drift.<br />
<br />
== Resources ==<br />
<br />
* [http://www.linuxsa.org.au/tips/time.html Linux Tips - Linux, Clocks, and Time]<br />
* [http://www.twinsun.com/tz/tz-link.htm Sources for Time Zone and Daylight Saving Time Data] for {{Pkg|tzdata}}<br />
* [http://www.ucolick.org/~sla/leapsecs/timescales.html Time Scales]<br />
* [[Wikipedia:Time]]</div>Tuxflo