Computer system time. Date, time and time zone

This page needs a maintainer

The article does not guarantee the relevance of the information. Help the Russian-speaking community by supporting pages like this. See ArchWiki Translation Team

IN operating system time (clock) is defined by four concepts: time value, time standard, time zone and, if necessary, summer time(Daylight Saving Time (DST)). This article explains each of them and how to read/set their values.

Contents

Introduction

The hardware clock is built into your computer, provides information about the year, month, day, hour, minute and second, and works even when it is turned off. They can count local (local) time or standard time UTC. More details on Wikipedia. In fact, local time is the time that your regular clock (for example, your grandmother's favorite clock) shows, and UTC time, without going into details, is the same for all residents globe, the reference point for which is the Greenwich meridian. In relation to UTC time, your local time may differ by several hours. Since you are reading the Russian version of the article, most likely your local time is longer from three to twelve hours compared to UTC.

All most common systems can use local or UTC time. By default, UNIX-like operating systems (including Mac OS) use UTC, while Windows uses local time. If you have several operating systems installed on your computer, it is best to use UTC in them to avoid conflicts.

On UNIX-like operating systems, the hardware clock can be checked and configured with the hwclock command.

In addition to the hardware clock, Linux also has a system (software) clock that operates independently. The system clock tracks the time, time zone, and controls whether your locale (the locale, as you remember, was configured during system installation in the /etc/locale.conf file) uses daylight saving time. The /etc/rc.d/hwclock daemon provides work with the hwclock command and sets the system time according to the hardware clock when loading the operating system and vice versa, adjusts hardware time upon completion of its work (after all, during its operation, the operating system can learn more exact time, for example from an NTP server). Therefore, users must include the "hwclock" daemon in the DAEMONS array in /etc/rc.conf for this to happen automatically. As an alternative to this daemon, users often use NTP to synchronize time with the so-called. Internet time servers.

Time standards

All most common operating systems can use local or UTC time. By default, UNIX-like operating systems (including Mac OS) use UTC, while Windows uses local time. If you have several operating systems installed on your computer, it is best to use UTC in them to avoid conflicts. GNU/Linux will switch to and from daylight saving time automatically only if you use UTC, regardless of whether it's daylight saving time or winter time. If you are using local time, GNU/Linux will not do the transition, assuming you have multiple operating systems and another operating system will do it for it. If this is not the case, then you will have to change the clock manually.

You can set the timing standard by means command line. First, check which standard you chose when installing the system:

$ grep ^HARDWARECLOCK /etc/rc.conf

If you are also using Windows, then best choice will localtime. To change the time standard to local time, use:

# hwclock --localtime

Or set the standard to UTC:

# hwclock --utc

After these operations, you will most likely need to update your hardware and system clock. See below .

Timezone

Make sure you set your time zone correctly in /etc/rc.conf, these values ​​are used not only for the clock, but also for other programs. To check the value, enter:

$ grep ^TIMEZONE /etc/rc.conf

You can view full list time zones in the file /usr/share/zoneinfo/ and select a major city in the same time zone as you. If you're not good at geography, you can always visit the Wikipedia page, which provides a complete list of time zones. In addition to specifying the nearest city, you can also select the time zone directly. Example:

TIMEZONE="America/Chicago"

The selected time zone will be picked up by the system after a reboot. To change the time zone immediately, you must link or copy the appropriate file to /etc/localtime:

# cp /usr/share/zoneinfo/America/Chicago /etc/localtime

Setting the time

The hardware clock can be set to the system clock. See what time is set on your hardware clock:

$hwclock --show

And the system clock:

To set the hardware clock directly:

# hwclock --set --date "MM/DD/YYYY hh:mm:ss"

Set system clock:

# date MMDDhhmmYYYY

The hardware clock can be set to the system clock and vice versa:

# hwclock --systohc # hwclock --hctosys

If there is no rc.conf file

To compare system time and UTC:

$timedatectl status

To set the system clock:

# timedatectl set-time "2012-10-30 18:17:16"

Change your zone and subzone:

# timedatectl set-timezone Zone/SubZone

List of available zones:

$timedatectl list-timezones

Example of setting zones:

# timedatectl set-timezone Europe/Moscow

Clock error

Nothing is perfect. Including hours. The time on any clock differs at least a little from the real one. Atomic clocks are considered one of the most accurate. Quartz clocks used in computers are also not absolutely accurate, but they have a relatively constant error.

Each time before shutting down, the hwclock daemon compares the hardware and system time (the latter is taken as the most accurate) and calculates the error of the hardware quartz clock per day. The calculated error value is written to the file /var/lib/hwclock/adjtime. If hwclock has not been used for more than a day, then, just in case, it calculates a new error value.

A special script adjusts the hardware clock in accordance with the calculated error every hour. If you see that your hardware clock is getting more and more incorrect, then most likely the error value stored in the /var/lib/hwclock/adjtime file is incorrect.

This happens if the time on the hardware clock was initially set incorrectly or your time standard (see above) is not the same as that of the other operating system used on the computer. To fix this, delete /var/lib/hwclock/adjtime and adjust the time on all your clocks.

Note: If you always turn off your computer more than once a day, the error recorded in /var/lib/hwclock/adjtime will not be rechecked by hwclock . A crystal oscillator is, of course, a reliable thing, but its parameters may change over time (for example CMOS battery discharges). Perhaps you should sometimes turn off your computer less than once a day. Then you can be sure that the error value by which the watch is adjusted will be the latest, and the watch will be the most accurate.

System time calculated by the kernel starting from midnight on the first of January 1st 1970 according to the UTC standard. The initial value of the system clock is calculated based on the hardware clock readings (after correcting the error and recalculating to the local UTC time zone) when turned on and runs independently of the hardware clock. Linux kernel keeps track of the system clock by counting timer interrupts. Like hardware ones, they are not perfectly accurate. Sometimes the system clock can become inaccurate if the kernel resets interrupts. But the system clock can be made accurate using NTP. NTP will adjust the interrupt rate and clock cycles per second to reduce system clock drift. These values ​​can be adjusted using the adjtimex application from AUR.

Note: If you are not using NTP, then your hardware clock will be more accurate than the system clock. Accordingly, the described correction mechanism will only introduce an additional error and it is better to disable it. To do this, you can comment out the line hwclock --systohc in the file ( /etc/rc.d/hwclock . Now when you turn off the computer, the system will not change the value of your hardware clock.

Time synchronization

Time Synchronization Protocol (NTP) is a protocol for synchronizing computer clocks using packets over networks with variable data delivery delays. Here are the implementations of this protocol:

  • Network Time Protocol daemon (Russian) is Wikipedia:ru: a reference implementation of the protocol, especially recommended for use on time servers. It also adjusts the interrupt frequency and clock cycles per second to reduce system clock drift, and will resynchronize the hardware clock every 11 minutes.
  • sntp- This

The following concepts are associated with the time used in the system: time zones, world time (Greenwich Mean Time), system time, job time. Any system or partition uses system time. The system time is displayed using the system time of day value.

System time is one of the most important concepts. However, there are other concepts that play a big role in time management. They are discussed below:

Local system time (system time) Local system time is obtained by adding to Greenwich time the difference with Greenwich time and the year difference specified in the system time zone. System value time of day contains exactly the local system time. The concepts of system time and local system time are equivalent. Local time of the task The local time of the task is obtained by adding to the Greenwich time the values ​​of the difference with the Greenwich time and the year difference specified in the time zone of the task. The local date and time of the job can be viewed on the Date/Time page containing the job properties. World Time (UTC) World time (Greenwich Mean Time) is used to calculate local system time and job time. Local system time is calculated by adding the difference from Greenwich Mean Time and the difference in years to the world time. Greenwich Mean Time Difference The difference between Universal Time (UTC, Greenwich Mean Time) and local system time, expressed in hours and minutes. A negative value corresponds to a deviation west of Greenwich, and a positive value corresponds to a deviation east of Greenwich. Year difference Year difference indicates how many years the current year of the calendar used by the system for a given time zone differs from the Gregorian calendar. Seasonal Time Seasonal Time (DST) is the part of the year when local time is ahead of the official standard time for a given region. Seasonal Time Difference Seasonal Time Difference is the number of minutes by which local time moves forward when switching to Daylight Saving Time or backwards when switching to Winter Time. Time Zone The Time Zone settings determine the difference from Greenwich Mean Time and also indicate whether seasonal time is applied. Each logical partition of the system can have its own time zone.

To illustrate the connection of these concepts with system time values, consider an example of two systems using different time zones.

The figure shows two systems in two different time zones. System A is in the Central Standard Time Zone, and System B is in the Beijing Standard Time Zone.

The system time values ​​for these systems are as follows:

System A System B
Local system time 10:00 20:00
Local job time 10:00 20:00
Timezone Central USA Moscow
Difference with Greenwich Time -6:00 +4:00
GMT 16:00 16:00

I want to describe a few interesting tricks with which you can change the display modes of the system clock, which is located in the lower right corner of the screen. All changes will be made using the Registry Editor.

In the registry branch HKEY_CURRENT_USER => Control Panel => International there is a string parameter sTimeFormat, which is responsible for the time display format we are used to. The default value of this parameter is H:mm:ss. If this parameter assign any other value, it will be displayed on the screen instead of the clock.

Below is a REG file with the parameter set to Tick-Tock:

“sTimeFormat”=”Tick-Tock”

(empty line)

Restart the computer - now instead of the usual time, the entered value will be displayed in the lower right corner of the monitor. To return to the initial state return the parameter sTimeFormat meaning HH:mm:ss and also restart your computer.

Please note that the length of the parameter value sTimeFormat must not exceed eight characters.

After changing the time format, the entered text will be displayed instead of the system time. However, the system implements the ability to display arbitrary text simultaneously with the time display. In the same registry branch, the parameter sTimeFormat assign the value in the format HH:mm Text, For example:

HH:mm Rush hour

Where " HH:mm” is the displayed time, and “Rush Hour” is the displayed text (remember, no more than 8 characters).

Windows Registry Editor Version 5.00

“sTimeFormat”=”HH:mm Rush Hour”

(empty line)

For the changes to take effect, restart your computer.

sTimeFormat meaning H:mm:ss and restart your computer.
Also, when editing the parameter sTimeFormat, you You can change the type of character separator in the system clock or swap the display of hours and minutes (mm:HH). To do this, just swap the letters mm and HH, placing them in the order in which you want to see the time. And, if you want to change the hour and minute separator, just change the colon character to the character you need.

The corresponding REG file will look like this:

Windows Registry Editor Version 5.00

“sTimeFormat”=”mm-HH”

(empty line)

After restarting the computer, the time will be displayed, for example, not as: “21:25”, but as: “25-21”. In principle, you can change (if you wish) only one of these two parameters.

To return the original system time display format, reassign the parameter sTimeFormat meaning H:mm:ss and restart your computer.

A very interesting trick: the inscription displayed next to the clock changes depending on the time of day. To do this, enter the registry editor branch HKEY_CURRENT_USER => Control Panel => International where you need create 2 string parameters with names s1159 And s2359 . The value assigned to the first parameter will be displayed next to the clock in the morning, and the value of the second parameter will be displayed next to the clock in the evening. The parameter itself sTimeFormat must be assigned a value HH:mm:ss tt.

Below is the text of the REG file in which the parameter s1159 assigned the value “ Good morning", and the parameter s2359 assigned the value “ Good evening":

Windows Registry Editor Version 5.00

"s1159"="Good morning"

"s2359"="Good evening"

"sTimeFormat"="HH:mm:ss tt"

(empty line)

To return to its original state, you need to return the parameter sTimeFormat meaning H:mm:ss and delete the entered parameters s1159 And s2359.

When performing the above tricks with the system clock, you should take into account that the corresponding changes may also appear in other places and modes of operation - for example, when receiving and sending letters to mail program Outlook Express.

The Windows 8 system clock is located in Notification areas located on the right side of the Taskbar. IN normal mode they demonstrate current time, if you hold the mouse cursor over them for a few seconds, a tooltip will appear on the screen indicating today's date. Clicking (or tapping) once on the system clock will open a dialog box that shows you the current date, a calendar, and a clock face showing the system time. To set the clock and calendar, click on the inscription Changing the date and time settings (Changedateandtimesettings) at the bottom of this window (Fig. 2.5).

Rice. 2.5. Date and time setting window

Date and time tab ( Dateandtime) Date and Time dialog box ( Dateandtime) allows you to set the current date and system time. To do this, click on the button Change date and time (Changedateandtime) at the top of this window. In the dialog box that appears on the screen Setting the time and date (Dateandtimesettings) a calendar is displayed in which the current date is marked with a bluish highlight. To select a different month in this calendar, use the buttons with the black arrows to the right and left of the designation current month, or single-click on a year to get a list of months from January to December. Clicking the year again will display a list of years on the screen from which you can select the desired year.

To change the time, touch the screen (click) inside the field located under the system clock image and enter the desired value using the keyboard.

If you want to change the time zone, click on the button Change time zone (Changetimezone) at the bottom of the Date and Time window ( Dateandtime). By expanding the menu at the top of the window, you can select the required time zone from the list.

In Windows 8, you can enable the display of an additional system clock that shows the current time in another region or time zone: this can be convenient if, for example, one of your relatives or friends lives in a remote geographic location, and sometimes you need to find out what time it is in his city without doing any calculations. To enable additional clocks, in the Date and Time window ( Dateandtime) open the tab Additional hours (Additionalclocks) and check the box Show these hours (Showthisclock). On the menu Select your time zone (Selecttimezone) you can specify the time zone for the selected hours, and in the field Display name (Enterdisplayname)— type an arbitrary watch name: say, name settlement, in which the clock shows the time, for example, "New York". Windows 8 allows you to enable two instances of additional clocks: you can add another clock by checking the box Show these hours (Showthisclock) at the bottom of the window. They are configured in the same way.

To set up an automatic mechanism for adjusting the system clock, go to the Internet Time tab of the Date and Time dialog box ( Dateandtime) and click on the button Change settings (Changesettings). Function Synchronization with an Internet time server (SynchronizewithanInternettimeserver) allows you to automatically synchronize the Windows system clock according to the reference time transmitted to the operating system specialized servers Internet networks. The server offered by default is time.windows.com, but the user can enter in the Server field the address of any other node configured for automatic synchronization systemic Windows clock 8.