Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a server running with the timezone set to UTC. It seemed like that was generally a good practice (please correct me if I'm wrong).

Anyhow, one of the servers I connect to, in order to scp files, is running on EDT and stores files that I need to copy in the format /path/to/filename/data20120913

I looked at trying to rsync files using something like find's -mtime -1 flag for files modified in the last day, but I didn't have any luck.

I don't mind just using scp to copy the current day's file, but as of right now there is a 4-hour window where running date +%Y%m%d will give a different day on each server and that bugs me a little.

Looking through man date I see that I can have the time output as UTC, but I don't see a way to have it output as another timezone like EDT

I suppose I could also use something like the GNU date extension date -d 20100909 +%s to get the date in seconds from the epoch, apply a manual 4 * 60 * 60 second calculation, and see about rendering that as a date - but then when daylight time kicks in it will still be an hour off.

Is there a simpler way to output the date in a YYYYMMDD format for EDT on a server that is set to UTC ?

share|improve this question
EDT is not a recognized timezone- in Linux, at least. See my "Be careful!" answer below for the whole ugly story. If EDT is recognized on your brand of *NIX, you should still exercise caution and double-check your timezone string. –  Mike S Mar 17 at 15:27

4 Answers 4

up vote 34 down vote accepted

You should be able to set a timezone for the duration of the query, thusly:

TZ=America/New_York date

Note the whitespace between the TZ setting and the date command. This sets the TZ variable only for the command line.

share|improve this answer
simple and beautiful. <3 linux –  cwd Sep 13 '12 at 21:45
+1 Beat me to it. –  James Sneeringer Sep 13 '12 at 21:59
I was able to find all of the timezones by inspecting the following directory: /usr/share/zoneinfo –  neowulf33 Oct 9 '14 at 21:41

You can do this by manipulating the TZ environment variable. The following will give you the local time for US/Eastern, which will also be smart enough to handle DST when that rolls around:

# all on one line
TZ=":US/Eastern" date +%Y%m%d

The zone name comes from the files and directories inside /usr/share/zoneinfo.

share|improve this answer
+1 - good call on the DST and thanks for sharing /usr/share/zoneinfo –  cwd Sep 13 '12 at 22:05

A bit funny, but I thought the obvious answer was TZ=EDT, since the one asking the question already knows his or her time zone code.

Alternatively, for those using shells other than bash and its cousins simply invoking TZ=EDT. For those shells there's the env command. Thus:

env TZ=EDT date
share|improve this answer

Be careful! Date will happily spit out the time in your CURRENT timezone, if you give it a timezone it doesn't recognize.

Check this out:

-bash-4.2$ env TZ=EDT date
Wed Feb 18 19:34:41 EDT 2015
-bash-4.2$ date
Wed Feb 18 19:34:43 UTC 2015

Note that there is no timezone called EDT. As a matter of fact,

-bash-4.2$ find /usr/share/zoneinfo -name "*EDT*"



And this works:

-bash-4.2$ TZ=EST5EDT date
Wed Feb 18 14:36:59 EST 2015
-bash-4.2$ date
Wed Feb 18 19:37:01 UTC 2015

However, if your friend lives in the mystic land of Gobbledygook and its zone info coincides with your own, you can have date output the time in Gobbledygook's zone and it will be happy to do so with nary an exit value to let you know that the zone is not known to it:

-bash-4.2$ TZ=Gobbledygook date
Wed Feb 18 19:37:36 Gobbledygook 2015
-bash-4.2$ echo $?
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.