Tuesday, July 12, 2011

converting to world date/timezones on linux, with the humble date

Playing with dates in linux, our humble date is well equipped.

  • Want the IST date, in case your host is a PDT/UTC one.
#TZ="Asia/Calcutta" date
  • Want a specific date (older)
# TZ="Asia/Calcutta" date -d "2011-07-10 19:58 PDT"
Mon Jul 11 08:28:00 IST 2011
  • Other way
# TZ="America/Los_Angeles" date -d "2011-07-10 7:58 IST"
Sat Jul 9 19:28:00 PDT 2011
  • If you need to find all the valid country specific timezone constants :
# ls -l /usr/share/zoneinfo/{continent}/{city}

  • Here is something cool you can do at your bash prompt:
PS1="[\$(TZ=\"Asia/Calcutta\" date +%D-%k:%M:%S) IST, \$(TZ=\"America/Los_Angeles\" date +%D-%k:%M:%S) PDT]"
PS1="$PS1\[\e[36m\]\u\[\e[0m\]"
PS1="$PS1@"

Shows me this
[07/12/11-17:32:24 IST, 07/12/11- 5:02:24 PDT]myname@myhost]$

2 comments:

Partha said...

Cool ... tried on Cygwin on my laptop (did not feel like doing VPN into servers) - works like a charm . You could probably wrap the TZ and date commands in a script and write a handy date converter.

BTW - came here from the Smondoville blog. Will try to visit more frequently :)

Cheers,

Partha

Sanjay Upadhyay said...

You are welcome :)

VIM issues with powerline

What to do if you get this annoying issue - vi requirements.txt ...