8

I use an Amazon EC2 server instance that runs a distro called Amazon Linux AMI. (I've read that it is based on CentOS/Red Hat). My specific version is the 2012.09 release.

Anyway, I was able to change the time zone about a week ago from the default UTC to America/New_York (which is EST/EDT). The command I used to change it was:

    ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

...thanks to this other Server Fault question. At that point, I was able to run date from the the command line, and it correctly displayed the EDT time. And even after EDT "fell back" to EST this past Sunday, I was pleased to find that running date still produced the correct local time. So that was great.

However, after running a yum update yesterday, it seems that my time zone got reverted back to plain 'ol UTC. I even checked the last modified time of /etc/localtime file, and indeed it confirmed that it had been modified around the same time I had updated.

Is there any way to prevent this from happening again, or will I be stuck resetting the time zone every time I do a yum update?

D.Tate
  • 205
  • 2
  • 6

2 Answers2

7

Make sure the time zone is also changed in

/etc/sysconfig/clock
by setting
ZONE="America/New_York"
kernelpanic
  • 1,276
  • 1
  • 10
  • 30
  • 1
    Thanks so much for the reply. I plan to accept your post if, after implementing your changes and running a `yum update` (when updates are available of course) my time zone does not revert. In the meantime, I checked `/etc/sysconfig/clock` and it has `ZONE="UTC"` and `UTC=true`. Do i need to make it say `UTC=false`? or do I only change ZONE? – D.Tate Nov 06 '12 at 17:26
  • 1
    Changing only the ZONE will suffice – kernelpanic Nov 06 '12 at 17:48
  • 1
    I am having the same issue. I changed the timezone in `/etc/timezone` but it reverts back to UTC every time I log out of the server. And for whatever reason `/etc/sysconfig` doesn't exist for me, so I can't modify the `clock` file. Any hints? – sixty4bit Aug 08 '14 at 17:01
  • What will for IST, I wrote ZONE="Indian", but it's not working. – Samir Apr 30 '19 at 09:47
0

Here's what I run on mine to keep them in Pacific Time:

sed -i '/ZONE/c \ZONE="America\/Los_Angeles"' /etc/sysconfig/clock
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
Jason Floyd
  • 1,792
  • 1
  • 13
  • 18
  • Thanks for the script Jason. kernelpanic mentioned that `UTC=false` is not necessary. If, after my testing, I find that it is necessary, I may very well mark your answer as the accepted one. – D.Tate Nov 07 '12 at 18:40
  • Let me know if it turns out you don't need it, I might be setting it false unnecessarily. – Jason Floyd Nov 10 '12 at 05:33
  • EC2 hardware clocks are in UTC so the UTC=false line shouldn't be added. – Jason Floyd Nov 10 '12 at 08:04
  • Thanks for the clarification Jason. I'm not sure if changing UTC to `false` will prevent the correct local time from displaying or not, but regardless, just leaving it at the default value of `UTC=true` seemed to be fine for me. If you want to "experiment" with various settings, I was able to test updates using `yum history undo [a number]` command. I would test `date` before and after the undo to see if it retained EST – D.Tate Nov 12 '12 at 18:27