Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 '15 at 15:27
up vote 67 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

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

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

The date syntax is arcane and error-prone, which makes a command-line invocation a pain. I therefore wrote a small script (I named it worldtime), which will print the specified (or current) time from base time zome (your local one) in some other time zones and the converse.

Here it is. Adjust it to match your needs, put it in your path, and make it executable.

# Print the specified (or current) time from base time in other time zones
# and the converse

# Base time zone from/to which to convert

# Time zones to display
# See /usr/share/zoneinfo/ for more names
TZONES='UTC America/Los_Angeles America/New_York Europe/London Europe/Paris'

# Display format
FORMAT='%H:%M (%p) %Z %a %m %b %Y'

if [ "$1" ] ; then
  time=`date +%T`

# Show the time from the specified input time zone in the specified output
# time zone

  TZ=$TZOUT date --date='TZ="'$TZIN'"'" $time" +"$time $TZIN is $TZOUT $FORMAT"

for tz in $TZONES ; do
  showtime $TZBASE $tz


for tz in $TZONES ; do
  showtime $tz $TZBASE

share|improve this answer
TODAY=$(TZ=":US/Eastern" date)
echo $TODAY
share|improve this answer
TODAY=TZ=":US/Eastern" date echo $TODAY – Lin Mar 31 '15 at 15:39
It's two lines: – Lin Mar 31 '15 at 15:40
You can edit your answer to fix the formatting. Use the preview function to see if it's how it should be. Otherwise, this question seems to already have proper answers. Also, we like it for answers to not be just code: it's much more helpful to future readers to explain in detail how your solution works. – dhag Mar 31 '15 at 15:46
It's two lines: #1: TODAY=TZ=":US/Eastern" date #2 echo $TODAY – Lin Mar 31 '15 at 15:48
don't copy and paste because some character not show up, go to edit to see detail – Lin Mar 31 '15 at 15:50

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.