(new Soapbox())->shout(array_map('strtoupper', $opinions)); //Shaun's blog


Me, elsewhere

GitHub
parseword
Miscellaneous public code

Twitter
@parseword
I don't tweet much

XMPP chat
xmpp@shaunc.com
(Pidgin, Miranda, Swift, etc.)


Perfect is the enemy of good enough.

Using TZ and "date" to find the current date and time anywhere on Earth

Posted December 14, 2015 by shaun

From a Linux terminal, if you need to find out what time it is in a different time zone or another country, you can use the date command. Just override the TZ environment variable when you run date:

[user@host ~]$ date
Mon Dec 14 22:10:59 CST 2015

[user@host ~]$ TZ=Poland date
Tue Dec 15 05:11:03 CET 2015

[user@host ~]$ TZ=Japan date
Tue Dec 15 13:11:07 JST 2015

[user@host ~]$ TZ=Australia/Melbourne date
Tue Dec 15 15:12:36 AEDT 2015

[user@host ~]$ TZ=Australia/Perth date
Tue Dec 15 12:12:41 AWST 2015

The full list of supported time zones will be somewhere on your filesystem; on many distributions, they're located at /usr/share/zoneinfo/. If you aren't sure where to find them, Wikipedia has a tz database that's mostly accurate.

Because some of the time zone names are cumbersome to remember and type, consider using aliases if you need to reference international times frequently. You can add commands like this to your .bash_profile or .bashrc,

alias nyctime='TZ=America/New_York date'
alias hktime='TZ=Asia/Hong_Kong date'
alias jtime='TZ=Japan date'

Now you can just run the aliases from your shell:

[user@host ~]$ date
Mon Dec 14 22:16:08 CST 2015

[user@host ~]$ jtime
Tue Dec 15 13:16:10 JST 2015

[user@host ~]$ nyctime
Mon Dec 14 23:16:14 CST 2015

This also works on FreeBSD, but the time zone naming scheme is different for many countries. For example, Japanese time is referenced on FreeBSD using TZ=Asia/Tokyo rather than TZ=Japan. Explore the contents of /usr/share/zoneinfo/ to find the zone you're looking for.



Recent articles

📰 Resolving "The lang/perl5.24 port has been deleted: Has expired" portmaster error

📰 Armagaddon2 interim fix for Firefox 56 and other old versions

📰 Strange DNS queries: qname "miep", qtype ANY

📰 Undeliverable as addressed: A massive broken spam campaign?

📰 Using WITH_META_MODE and ccache for FreeBSD build boosts

📰 Resolving subversion error E000013: Unable to create pristine install stream

📰 Enhancements to SmokePing's AnotherDNS probe

📰 Generating vanity DNSSEC key tags

📰 DDoS involving forged packets from 23.225.141.70

📰 Website integrity monitoring through version control

📰 SpamAssassin 3.4.2 fixes security problems, adds HashBL and phishing plugins

📰 Bug or turf war? ICQ via Pidgin now fails with "startOSCARSession: Request Timeout"

📰 🎂

📰 SFSQuery, a PHP class to query the StopForumSpam API and DNSBL

📰 Resolving portmaster error "pkg-static: automake-1.16.1 conflicts with automake-wrapper-20131203"

▲ Back to top | Permalink to this page