Skip to content

Instantly share code, notes, and snippets.

@dominique-mueller
Last active January 19, 2021 22:13
Show Gist options
  • Save dominique-mueller/f823e2eb6972c741598843e4641143d9 to your computer and use it in GitHub Desktop.
Save dominique-mueller/f823e2eb6972c741598843e4641143d9 to your computer and use it in GitHub Desktop.
Switch timezone on linux systems. Very helpful when running tests on a CI and verifying that timezone logic works properly.
# Switch the timezone on a linux system
#
# I use this to run unit tests on the CI for multiple times with different timezones (at least 2)
# Tested on a node alpine docker container on GitLab CI
# Timezone values: "UTC", "Europe/Berlin", ...
# Fetch timezone data
- apk add tzdata
# Log out number of timeszones (debug)
- ls -1 /usr/share/zoneinfo/ | wc -l
# Copy desired timezone to system
- cp /usr/share/zoneinfo/UTC /etc/localtime
# Set desired timezone
- echo "UTC" > /etc/timezone
# Log current date in defined timezone (debug)
- date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment