6

I have set the date & time but once I logout, it sets time back to old time slot.

How can I set the time permanently? I have used the tzselect command & then export localtime.

3
  • 4
    which Linux OS do you have ?
    – Rahul
    Aug 11, 2016 at 11:13
  • 3
    do you actually want to set date & time or do you want to change the timezone? if the former, to what date and time does your machine set it back to?
    – madeddie
    Aug 11, 2016 at 11:37
  • 1
    Are you booting from a recovery or installation media, or from a hard / SSD drive? Aug 13, 2016 at 3:57

1 Answer 1

7

If systemd based system, here you are ↴

Date and Time

$ timedatectl set-time 'YYYY-MM-DD HH:MM:SS'

And if you want to change the date or time only:

$ timedatectl set-time HH:MM:SS       /*for time only*/

$ timedatectl set-time YYYY-MM-DD     /*for date only*/

To verify the change:

$ timedatectl

To print the system date and time:

$ date

TimeZone

You can use timedatectl as shown below to list the available timezones

$ timedatectl list-timezones

To select one:

$ timedatectl set-timezone 'yourNewTimeZone' 

N.B. And if you want to use tzselect, be aware that for the change to be permanent, you need to add your export-line - for instance TZ='yourNewTimeZone'; export TZ in $HOME/.bash_profile or $HOME/.bashrc. BTW, be aware that tzselect command does not actually change the timezone for you.

1
  • also disable ntp first before setting to prevent error timedatectl set-ntp no, set the time, then set the hardware clock hwclock -w, then turn on back the ntp timedatectl set-ntp yes, assuming you already have correct timezone
    – Kokizzu
    Jul 22, 2020 at 19:40

Not the answer you're looking for? Browse other questions tagged .