Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have friends all over the globe and before calling them I need to know their current time. Is there an application in Linux where one can query a city (if exists) in terminal (something like this): time miami

P.S: Yes I know that I can query it from Google but I prefer using the terminal

share|improve this question

1 Answer 1

up vote 10 down vote accepted

The date command will give you the current date/time based on your locale.
You can change that, one time only, by prefixing the command with a different timezone

TZ=CST6CDT date # Will print the current time in the USA Central time
TZ=Chicago date # will do the same, iff Chicago is listed by name in the /usr/share/zoneinfo/ dir hierarchy

Then to simplify ease of access, just create aliases in you .bashrc file, eg.

alias dad='TZ=Paris date'
alias fred='TZ=Amsterdam date'

etc.

share|improve this answer
    
very nice answer, thanks. let's say i want miami (not listed under /usr/share/zoneinfo/) and how do i find out its zone code (CST6...)? –  sterz Mar 8 '12 at 18:54
1  
You could use google maps or earth, but in this case I'll just tell you. Miami is in the Eastern Time zone, EST5EDT, same as New_York (Miami's just a little further south). Quick G search, found and like this, gives TZ –  bdowning Mar 8 '12 at 19:26
1  
“in the /usr/share/zoneinfo hierarchy”? I've never seen that. AFAIK you need the full path from the zoneinfo directory, e.g. TZ=America/Chicago or TZ=Europe/Paris or TZ=Hongkong. –  Gilles Mar 8 '12 at 23:18
    
Nope, just the City is enough, again I speak empirically. I tried it, and it works. I'm in America but the TZ=Paris worked fine. If I were going to rely on this, personally I'd stick with the EST5DST form. –  bdowning Mar 8 '12 at 23:26
    
Seems Gilles is right. It works for me only with full path. –  manatwork Mar 9 '12 at 8:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.