Configuration de la date et de l’heure
Les systèmes d’exploitation modernes font la distinction entre les deux types d’horloge suivants :
-
une horloge temps réel (real-time clock, RTC), également appelée communément horloge matérielle (généralement un circuit intégré sur la carte mère) qui est complètement indépendante de l’état actuel du système d’exploitation et qui s’exécute même lorsque l’ordinateur est éteint ;
-
une horloge système, également connue sous le nom d'horloge logicielle, maintenue par le noyau et dont la valeur initiale est basée sur l’horloge temps réel. Une fois que le système est démarré et que l’horloge système est initialisée, cette dernière devient complètement indépendante de l’horloge temps réel.
L’heure du système est toujours au temps universel coordonné (coordinated universal time, UTC) et converties dans les applications en heure locale si nécessaire. L’heure locale est l’heure dans votre fuseau horaire, elle prend en compte le décalage horaire (daylight saving time, DST). L’horloge temps réel peut être réglée à l’UTC ou à l’heure locale. UTC est recommandé.
Fedora Rawhide offre trois outils en ligne de commande qui peuvent être utilisés pour configurer et obtenir des informations sur la date et l’heure du système : l’utilitaire timedatectl, nouveau dans Fedora Rawhide et faisant partie de systemd
, la commande traditionnelle date et l’utilitaire hwclock pour accéder à l’horloge matérielle.
Utilisation de la commande timedatectl
L’utilitaire timedatectl est distribué avec systemd
, le gestionnaire du système et des services, et vous permet d’examiner et modifier la configuration de l’horloge système. Vous pouvez utiliser cet outil pour modifier la date et l’heure, définir le fuseau horaire ou activer la synchronisation automatique de l’horloge système avec un serveur distant.
Pour savoir comment afficher la date et l’heure dans un format personnalisé, consultez aussi Utilisation de la commande date.
Affichage de la date et de l’heure
Pour afficher la date et l’heure ainsi que des informations détaillées à propos de la configuration du système et de l’horloge système, exécutez la commande timedatectl sans ajouter d’options à la ligne de commande :
timedatectl
Cette commande affiche l’heure locale et universelle, le fuseau horaire utilisé actuellement, l’état de la configuration Network Time Protocol (NTP
) et d’autres informations à propos de l’heure d’été.
Voici une sortie d’exemple de la commande timedatectl sur un système n’utilisant pas NTP
pour synchroniser l’horloge système avec un serveur distant :
~]$ timedatectl Local time: Mon 2013-09-16 19:30:24 CEST Universal time: Mon 2013-09-16 17:30:24 UTC Timezone: Europe/Prague (CEST, +0200) NTP enabled: no NTP synchronized: no RTC in local TZ: no DST active: yes Last DST change: DST began at Sun 2013-03-31 01:59:59 CET Sun 2013-03-31 03:00:00 CEST Next DST change: DST ends (the clock jumps one hour backwards) at Sun 2013-10-27 02:59:59 CEST Sun 2013-10-27 02:00:00 CET
Modification de l’heure actuelle
Pour modifier l’heure actuelle, tapez la commande suivante dans un shell s’exécutant en tant que root
:
timedatectl set-time
HH:MM:SS
Remplacez HH par l’heure désirée, MM par la minute désirée et SS par la seconde désirée, toutes sur deux chiffres.
Cette commande met à jour à la fois l’heure du système et l’horloge matérielle. Le résultat est similaire à l’utilisation des commandes date --set et hwclock --systohc.
La commande échouera si un service NTP
est activé. Consultez Synchronisation de l’horloge système avec un serveur distant pour désactiver temporairement le service.
Pour définir l’heure actuelle à 23:26, exécutez la commande suivante en tant que root
:
~]# timedatectl set-time 23:26:00
Par défaut, le système est configuré de façon à utiliser UTC. Pour configurer votre système de façon à maintenir l’horloge dans l’heure locale, exécutez en tant que root
la commande timedatectl avec l’option set-local-rtc
:
timedatectl set-local-rtc
boolean
Pour configurer votre système de façon à maintenir l’horloge à l’heure locale, remplacez boolean par yes
(y
, true
, t
et même`1` fonctionnent également). Pour configurer le système de façon à utiliser UTC, remplacez boolean par no
(n
, false
, f
et 0
fonctionnent aussi). L’option par défaut est no
.
Modification de la date actuelle
Pour modifier la date actuelle, tapez la commande suivante dans un shell s’exécutant en tant que root
:
timedatectl set-time
AAAA-MM-JJ
Remplacez AAAA par une année sur quatre chiffres, MM par un mois sur deux chiffres et _JJ par un jour sur deux chiffres.
Notez que modifier la date sans spécifier l’heure actuelle a pour effet de définir l’heure à 00:00:00.
Pour définir la date actuelle au 2 juillet 2013 et conserver l’heure actuelle (23:26), exécutez la commande suivante en tant que root
:
~]# timedatectl set-time "2013-06-02 23:26:00"
Changement de fuseau horaire
Pour lister les fuseaux horaires disponibles, tapez la commande suivante dans un shell :
timedatectl list-timezones
Pour changer de fuseau horaire, tapez la commande suivante en tant que root
:
timedatectl set-timezone time_zone
Remplacez time_zone par l’une des valeurs listées par la commande timedatectl list-timezones.
Pour identifier le fuseau horaire correspondant à votre emplacement, utilisez la commande timedatectl avec l’option en ligne de commande list-timezones
. Par exemple, pour lister les fuseaux horaires d’Europe, tapez :
~]# timedatectl list-timezones | grep Europe Europe/Amsterdam Europe/Andorra Europe/Athens Europe/Belgrade Europe/Berlin Europe/Bratislava …
Pour définir le fuseau horaire sur Europe/Prague
, tapez la commande suivante en tant que root
:
~]# timedatectl set-timezone Europe/Prague
Synchronisation de l’horloge système avec un serveur distant
Pour éviter les ajustements manuels décrits dans les sections précédentes, il est possible d’utiliser la commande timedatectl pour activer la synchronisation automatique de votre horloge système avec un groupe de serveurs distants en utilisant le protocole NTP
. L’activation de NTP active le service chronyd
ou ntpd
, en fonction de celui qui est installé.
Le service NTP
peut être activé et désactivé en utilisant une commande telle que la suivante :
timedatectl set-ntp
boolean
Pour activer la synchronisation de l’horloge système avec un serveur NTP
distant, remplacez boolean par yes
(option par défaut). Pour désactiver cette fonctionnalité, remplacez boolean par no
.
Pour activer la synchronisation automatique de l’horloge système avec un serveur distant, tapez :
~]# timedatectl set-ntp yes
La commande échouera si aucun service NTP
n’est installé. Consultez Installation de chrony pour plus d’informations.
Utilisation de la commande date
L’utilitaire date est disponible sur tous les systèmes Linux et vous permet d’afficher et de configurer la date et l’heure. Il est utilisé fréquemment dans les scripts pour afficher des informations détaillées à propos de l’horloge système dans un format personnalisé.
Pour savoir comment changer de fuseau horaire ou activer la synchronisation automatique de l’horloge système avec un serveur distant, consultez Utilisation de la commande timedatectl.
Affichage de la date et de l’heure
Pour afficher la date et l’heure, exécutez la commande date sans ajouter d’options à la ligne de commande :
date
Cette commande affiche le jour de la semaine suivi de la date actuelle, l’heure locale, le fuseau horaire et l’année.
Par défaut, la commande date affiche l’heure locale. Pour afficher l’heure en UTC, exécutez la commande avec l’option --utc
ou -u
:
date --utc
Vous pouvez aussi personnaliser le format d’affichage des informations en spécifiant l’option +"format"
sur la ligne de commande :
date +"format"
Remplacez format par une ou plusieurs séquences de contrôle comme détaillé dans Affichage de la date et de l’heure. Consultez Séquences de contrôle utilisées communément pour une liste des options de formatage les plus utilisées, ou la page de manuel date
(1) pour une liste complète de ces options.
Control Sequence | Description |
---|---|
|
The hour in the HH format (for example, |
|
The minute in the MM format (for example, |
|
The second in the SS format (for example, |
|
The day of the month in the DD format (for example, |
|
The month in the MM format (for example, |
|
The year in the YYYY format (for example, |
|
The time zone abbreviation (for example, |
|
The full date in the YYYY-MM-DD format (for example, |
|
The full time in the HH:MM:SS format (for example, 17:30:24). This option is equal to |
To display the current date and local time, type the following at a shell prompt:
~]$ date
Mon Sep 16 17:30:24 CEST 2013
To display the current date and time in UTC, type the following at a shell prompt:
~]$ date --utc
Mon Sep 16 15:30:34 UTC 2013
To customize the output of the date command, type:
~]$ date +"%Y-%m-%d %H:%M" 2013-09-16 17:30
Modification de l’heure actuelle
To change the current time, run the date command with the --set
or -s
option as root
:
date --set
HH:MM:SS
Remplacez HH par l’heure désirée, MM par la minute désirée et SS par la seconde désirée, toutes sur deux chiffres.
By default, the date command sets the system clock to the local time. To set the system clock in UTC, run the command with the --utc
or -u
command line option:
date--set
HH:MM:SS--utc
Pour définir l’heure actuelle à 23:26, exécutez la commande suivante en tant que root
:
~]# date --set 23:26:00
Modification de la date actuelle
To change the current date, run the date command with the --set
or -s
option as root
:
date --set
YYYY-MM-DD
Remplacez AAAA par une année sur quatre chiffres, MM par un mois sur deux chiffres et _JJ par un jour sur deux chiffres.
Notez que modifier la date sans spécifier l’heure actuelle a pour effet de définir l’heure à 00:00:00.
Pour définir la date actuelle au 2 juillet 2013 et conserver l’heure actuelle (23:26), exécutez la commande suivante en tant que root
:
~]# date --set 2013-06-02 23:26:00
Using the hwclock Command
hwclock
is a utility for accessing the hardware clock, also referred to as the Real Time Clock (RTC). The hardware clock is independent of the operating system you use and works even when the machine is shut down. This utility is used for displaying the time from the hardware clock. hwclock
also contains facilities for compensating for systematic drift in the hardware clock.
The hardware clock stores the values of: year, month, day, hour, minute, and second. It is not able to store the time standard, local time or Coordinated Universal Time (UTC), nor set the Daylight Saving Time (DST).
The hwclock
utility saves its settings in the /etc/adjtime
file, which is created with the first change you make, for example, when you set the time manually or synchronize the hardware clock with the system time.
In Fedora 6, the hwclock command was run automatically on every system shutdown or reboot, but it is not in Fedora Rawhide. When the system clock is synchronized by the Network Time Protocol (NTP) or Precision Time Protocol (PTP), the kernel automatically synchronizes the hardware clock to the system clock every 11 minutes. |
For details about NTP, see Configuring NTP Using the chrony Suite and Configuring NTP Using ntpd. For information about PTP, see Configuring PTP Using ptp4l. For information about setting the hardware clock after executing ntpdate, see Configuring the Hardware Clock Update.
Affichage de la date et de l’heure
Running hwclock with no command line options as the root
user returns the date and time in local time to standard output.
hwclock
Note that using the --utc
or --localtime
options with the hwclock command does not mean you are displaying the hardware clock time in UTC or local time. These options are used for setting the hardware clock to keep time in either of them. The time is always displayed in local time. Additionally, using the hwclock --utc or hwclock --local commands does not change the record in the /etc/adjtime
file. This command can be useful when you know that the setting saved in /etc/adjtime
is incorrect but you do not want to change the setting. On the other hand, you may receive misleading information if you use the command an incorrect way. See the hwclock
(8) manual page for more details.
To display the current date and the current local time from the hardware clock, run as root
:
~]# hwclock Tue 15 Apr 2014 04:23:46 PM CEST -0.329272 seconds
CEST is a time zone abbreviation and stands for Central European Summer Time.
For information on how to change the time zone, see Changing the Time Zone.
Setting the Date and Time
Besides displaying the date and time, you can manually set the hardware clock to a specific time.
When you need to change the hardware clock date and time, you can do so by appending the --set
and --date
options along with your specification:
hwclock --set --date "dd mmm yyyy HH:MM"
Replace dd with a day (a two-digit number), mmm with a month (a three-letter abbreviation), yyyy with a year (a four-digit number), HH with an hour (a two-digit number), MM with a minute (a two-digit number).
At the same time, you can also set the hardware clock to keep the time in either UTC or local time by adding the --utc
or --localtime
options, respectively. In this case, UTC
or LOCAL
is recorded in the /etc/adjtime
file.
If you want to set the date and time to a specific value, for example, to "21:17, October 21, 2014", and keep the hardware clock in UTC, run the command as root
in the following format:
~]# hwclock --set --date "21 Oct 2014 21:17" --utc
Synchronizing the Date and Time
You can synchronize the hardware clock and the current system time in both directions.
-
Either you can set the hardware clock to the current system time by using this command:
hwclock --systohc
Note that if you use NTP, the hardware clock is automatically synchronized to the system clock every 11 minutes, and this command is useful only at boot time to get a reasonable initial system time.
-
Or, you can set the system time from the hardware clock by using the following command:
hwclock --hctosys
When you synchronize the hardware clock and the system time, you can also specify whether you want to keep the hardware clock in local time or UTC by adding the --utc
or --localtime
option. Similarly to using --set
, UTC
or LOCAL
is recorded in the /etc/adjtime
file.
The hwclock --systohc --utc command is functionally similar to timedatectl set-local-rtc false and the hwclock --systohc --local command is an alternative to timedatectl set-local-rtc true.
To set the hardware clock to the current system time and keep the hardware clock in local time, run the following command as root
:
~]# hwclock --systohc --localtime
To avoid problems with time zone and DST switching, it is recommended to keep the hardware clock in UTC. The shown Synchronizing the Hardware Clock with System Time is useful, for example, in case of a multi boot with a Windows system, which assumes the hardware clock runs in local time by default, and all other systems need to accommodate to it by using local time as well. It may also be needed with a virtual machine; if the virtual hardware clock provided by the host is running in local time, the guest system needs to be configured to use local time, too.
Ressources supplémentaires
For more information on how to configure the date and time in Fedora Rawhide, see the resources listed below.
-
timedatectl
(1) — The manual page for the timedatectl command line utility documents how to use this tool to query and change the system clock and its settings. -
date
(1) — The manual page for the date command provides a complete list of supported command line options. -
hwclock
(8) — The manual page for the hwclock command provides a complete list of supported command line options.
-
System Locale and Keyboard Configuration documents how to configure the keyboard layout.
Want to help? Learn how to contribute to Fedora Docs ›