Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 403
Robert Ranjan Avatar asked Dec 18 '22 14:12

Robert Ranjan


1 Answers

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.

Example:

$ 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
like image 63
heemayl Avatar answered May 19 '23 02:05

heemayl