filmov
tv
Unix & Linux: How can I have `date` output the time from a different timezone? (6 Solutions!!)

Показать описание
Unix & Linux: How can I have `date` output the time from a different timezone?
The Question: 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 ?
Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful
The Question: 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 ?
Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful