Skip to main content

Update Timezone Data

Check Current TZ Data

timedatectl

Update TZ

timedatectl set-timezone America/Phoenix

List TZ

timedatectl list-timezones

Search For TZ in Specific Area

timedatectl list-timezones | grep America

Search For Specific TZ

timedatectl list-timezones | grep Phoenix

TZ Data is Stored Here (Debian)

ls /usr/share/zoneinfo

Script to Update Containers

I stored this script in the Proxmox Shell's root directory so I can periodically run it when I forget to set the TZ. I know there is a way to set LXC templates up with this info, but sometimes it's easier to just re-run this to ensure all is well.

#!/bin/bash

# Get list of container IDs
container_ids=$(pct list | awk 'NR>1 {print $1}')

echo "Updating timezone to America/Phoenix for the following containers: $container_ids"

for ctid in $container_ids; do
  echo "Processing container ID: $ctid"

  # Attempt Debian/Ubuntu method
  if pct exec $ctid -- which dpkg-reconfigure > /dev/null 2>&1; then
    echo "  Detected Debian/Ubuntu-based container. Updating timezone..."
    pct exec $ctid -- apt-get update && apt-get install -y tzdata locales -qq
    pct exec $ctid -- echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
    pct exec $ctid -- dpkg-reconfigure --frontend=noninteractive locales -f
    # Directly set environment variables for the tzdata reconfiguration
    pct exec $ctid -- env LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 dpkg-reconfigure --frontend=noninteractive tzdata
    pct exec $ctid -- ln -sf /usr/share/zoneinfo/America/Phoenix /etc/localtime
    pct exec $ctid -- echo "America/Phoenix" > /etc/timezone
    pct exec $ctid -- date
  elif pct exec $ctid -- which timedatectl > /dev/null 2>&1; then
    echo "  Detected systemd-based container. Updating timezone..."
    pct exec $ctid -- timedatectl set-timezone America/Phoenix
    pct exec $ctid -- date
  elif pct exec $ctid -- which apk > /dev/null 2>&1; then
    echo "  Detected Alpine Linux-based container. Updating timezone..."
    pct exec $ctid -- apk update && apk add --no-cache tzdata -qq
    pct exec $ctid -- ln -sf /usr/share/zoneinfo/America/Phoenix /etc/localtime
    pct exec $ctid -- echo "America/Phoenix" > /etc/timezone
    pct exec $ctid -- date
  else
    echo "  Could not determine the OS type for container $ctid. Please update manually."
    echo "  Try running: pct exec $ctid -- dpkg-reconfigure tzdata"
    echo "  or: pct exec $ctid -- timedatectl set-timezone America/Phoenix"
    echo "  or: pct exec $ctid -- ln -sf /usr/share/zoneinfo/America/Phoenix /etc/localtime"
    echo "  and: pct exec $ctid -- echo 'America/Phoenix' > /etc/timezone"
  fi
  echo "-------------------------"
done

echo "Timezone update process completed."