Robert Ranjan Robert Ranjan - 2 months ago 5
Linux Question

how to get local date/time in linux terminal while server configured in UTC/different timezone?

how to get local date & time in linux terminal while server configured in UTC or different timezone?

here is what I get now but I'd like to see in local timezone. For eg: PST/PDT.

[jenkins@myServer ~]$ date
Thu Jul 28 18:16:48 UTC 2016

I'm not looking to change system time using hwclock or updating /etc/localtime. Just want to change it for a user.

Also, please let me know - how to persist it for future logins.


Use the TZ environment variable to pass the desired timezone to date:

TZ=<timezone> date

You can find the available timezones in the /usr/share/zoneinfo/ directory and subdirectories. For example, /usr/share/zoneinfo/America/New_York defines TZ=America/New_York.


$ date                         
Fri Jul 29 06:31:53 BDT 2016

$ TZ='America/New_York' date   
Thu Jul 28 20:31:58 EDT 2016

$ TZ='America/Los_Angeles' date
Thu Jul 28 17:31:54 PDT 2016