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]$

List directories via 'ls -d' - surprised me

List directories via 'ls -d' - surprised me This was one of those feelings where I was left surprised with the humble linux comm...