Skip to content

Instantly share code, notes, and snippets.

@nick-desteffen
Created August 5, 2011 01:50
Show Gist options
  • Save nick-desteffen/1126771 to your computer and use it in GitHub Desktop.
Save nick-desteffen/1126771 to your computer and use it in GitHub Desktop.
Set Time zone in OSX to UTC
sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime
@paul3412
Copy link

paul3412 commented Jul 13, 2020

works on MacOs Mojave thanks !
any tip to revert this (in case i need to in the future)

@Gerst20051
Copy link

Gerst20051 commented Mar 15, 2022

Command To See What Your Local Time Is Currently Set To:

[$]> ls -la /etc/localtime

/etc/localtime -> /var/db/timezone/zoneinfo/America/Los_Angeles

Command To Set Your Local Time To UTC

[$]> sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime

NOTE: When I Set It To UTC - United Kingdom Via System Preferences It Becomes:

[$]> ls -la /etc/localtime

/etc/localtime -> /var/db/timezone/zoneinfo/UTC

Command To Switch Your Local Time Back To The Original Time Zone

[$]> sudo ln -sf /var/db/timezone/zoneinfo/America/Los_Angeles /etc/localtime

FYI: I Compared Both Of The UTC Files And They Are Exactly Matching

[$]> delta /usr/share/zoneinfo/UTC /var/db/timezone/zoneinfo/UTC
or
[$]> diff /usr/share/zoneinfo/UTC /var/db/timezone/zoneinfo/UTC

[$]> cat /usr/share/zoneinfo/UTC /var/db/timezone/zoneinfo/UTC

TZif2UTCTZif2UTC
UTC0
TZif2UTCTZif2UTC
UTC0

I created the following shell aliases to make switching timezones easy.

# output the current timezone
alias timezone.current='exa -l /etc/localtime'

# set the timezone to my default local timezone
alias timezone.default='sudo ln -sf /var/db/timezone/zoneinfo/America/Los_Angeles /etc/localtime'

# set the timezone to utc
alias timezone.utc='sudo ln -sf /var/db/timezone/zoneinfo/UTC /etc/localtime'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment