Setting the Date and Time
This section discusses how to set the time zone, and how to set the date and time on the software clock on the switch. To configure NTP, see Network Time Protocol - NTP. To configure PTP, see Precision Time Protocol - PTP.
Setting the time zone, and the date and time on the software clock requires root privileges; use sudo
.
Show the Current Time Zone, Date, and Time
To show the current time zone, date, and time on the switch:
cumulus@switch:~$ nv show system date-time
operational
------------------------- -----------------------------
local-time Wed 2023-11-22 11:22:54 EST
universal-time Wed 2023-11-22 16:22:54 UTC
rtc-time Wed 2023-11-22 16:22:54
time-zone America/New_York (EST, -0500)
system-clock-synchronized no
ntp-service inactive
rtc-in-local-tz no
unix-time 1700670174.4371066
cumulus@switch:~$ date
Wed 11 Oct 2023 12:18:33 PM UTC
To show the time zone only, run the date +%Z
command:
cumulus@switch:~$ date +%Z
UTC
Set the Time Zone
You can use one of these methods to set the time zone on the switch:
- Run NVUE commands.
- Use the guided wizard.
- Edit the
/etc/timezone
file.
Run the nv set system timezone <timezone>
command. To see all the available time zones, run nv set system timezone
and press the Tab key. The following example sets the time zone to US/Eastern:
cumulus@switch:~$ nv set system timezone US/Eastern
cumulus@switch:~$ nv config apply
-
In a terminal, run the following command:
cumulus@switch:~$ sudo dpkg-reconfigure tzdata
-
Follow the on screen menu options to select the geographic area and region.
-
Edit the
/etc/timezone
file to add your desired time zone. You can see a list of valid time zones here.cumulus@switch:~$ sudo vi /etc/timezone US/Eastern
-
Apply the new time zone:
cumulus@switch:~$ sudo dpkg-reconfigure --frontend noninteractive tzdata
-
Change
/etc/localtime
to reflect your current time zone:sudo ln -sf /usr/share/zoneinfo/US/Eastern /etc/localtime
Set the Date and Time
The switch contains a battery backed hardware clock that maintains the time while the switch powers off and between reboots. When the switch is running, the Cumulus Linux operating system maintains its own software clock.
During boot up, the switch copies the time from the hardware clock to the operating system software clock. The software clock takes care of all the timekeeping. During system shutdown, the switch copies the software clock back to the battery backed hardware clock.
If you need to reconfigure the current time zone, refer to the instructions above.
To set the software clock according to the configured time zone:
Run the nv action change system date-time <clock-date> <clock-time>
command. Specify <clock-date>
in YYYY-MM-DD format and <clock-time>
in HH:MM:SS format.
cumulus@switch:~$ nv action change system date-time 2023-12-04 2:33:30
System Date-time changed successfully
Local Time is now Mon 2023-12-04 02:33:30 UTC
Action succeeded
cumulus@switch:~$ sudo date -s "Tue Jan 26 00:37:13 2021"
You can write the current value of the software clock to the hardware clock using the hwclock
command:
cumulus@switch:~$ sudo hwclock -w
See man hwclock(8)
for more information.