Search This Blog

2010-01-14

Display UNIX Date with Timezone

Following is a trick to display UNIX date in any timezone without permanently changing TZ variable.

$ TZ=EST5EDT date "+%F %T %z"
2010-01-14 16:49:17 -0500

This is what it does is similar to below
$ TZ2=$TZ
$ TZ=EST5EDT
$ date "+%F %T %z"
$ TZ=$TZ2
$ unset TZ2

It won't change the current value stored in TZ as well
$ date
Thu Jan 14 21:50:02 GMT 2010
$ export TZ=CST6CET
$ date
Thu Jan 14 15:50:39 CST 2010
$ TZ=EST5EDT date "+%F %T %z"
2010-01-14 16:50:47 -0500
$ echo $TZ
CST6CET
$ date
Thu Jan 14 15:50:53 CST 2010

No comments:

Blog Archive