Friday, July 3, 2009

Using Unix date command for timezone conversion

I do a lot of work with developers in Bangalore, and am always wanting to do date calculations to figure out what time it is there. Using the TZ environment variable, it is easy to do this using plain old date (I am using 7.4 from GNU coreutils).

For example, what time is it right now in India?

$ TZ=Asia/Calcutta date
Sat Jul 4 00:40:41 IST 2009


I want to hold a meeting at 9am, what time will it be in India?

$ TZ=Asia/Calcutta date -d '9am EDT'
Sat Jul 4 18:30:00 IST 2009


There's a meeting on Friday at 4pm in India, what time will it be here?

$ date -d 'Fri 4pm IST'
Fri Jul 3 06:30:00 EDT 2009


For extra goodness, if you use zsh, do TZ=[TAB] and the shell will complete available timezones for you.

No comments:

Post a Comment