17

What's the best approach for configuring the Time Zone non-interactively?

Previously for hostname, I've used

sudo raspi-config nonint do_hostname

However, I am unable to locate the equivalent command for timezone?

Greenonline
  • 2,740
  • 4
  • 23
  • 36
ljtill
  • 173
  • 1
  • 1
  • 5

2 Answers2

33

use timedatectl - for example

sudo timedatectl set-timezone Australia/Sydney
Jaromanda X
  • 2,415
  • 1
  • 13
  • 14
2

The time zone is set by a symbolic link from /etc/localtime to a file in the /usr/share/zoneinfo directory.

The time zone needs to be in the form 'Area/Location' where these conform to the standards used in Linux. E.g. for Area use Africa, America, Antarctica, Arctic, Asia, Atlantic, Australia, Europe, Indian, and Pacific.

For Location use the name of a specific location within the Area. This is usually a city or small island.

See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for details

For example for New Zealand use Pacific/Auckland

  • First you need to remove /etc/localtime, otherwise /etc/timezone will be overwritten.
  • Then create your link
  • Then remove /etc/timezone

The commands I run are;

sudo rm /etc/localtime
sudo ln -s /usr/share/zoneinfo/Pacific/Auckland /etc/localtime
sudo rm /etc/timezone

Edit: Now I'm looking at it I don't exactly know why I'm removing /etc/timezone. Eeek!

d3noob
  • 1,876
  • 1
  • 15
  • 15
  • 2
    This answer explains how time zones are (currently) implemented, however, the "right" answer is @JaromandaX's answer below. Use timedatectl, abstractions are your friend. – dlu May 05 '20 at 18:35