I find it’s pretty annoying when you have to go log file spelunking only to find all the timestamps are in UTC. But we can set the timezone of the server so when Rails, cron, scripts, etc run, they output more readable dates.
You can check your current timezone by just running
Thu Mar 21 18:02:49 MST 2012
Or checking the timezone file at
US/Arizona
So to change it just run
And follow on screen instructions. Easy.
Also be sure to restart cron as it won’t pick up the timezone change and will still be running on UTC.
$ /etc/init.d/cron start
UPDATE July 2016
In the comments Dan mentions that in 16.04 you use something like:
{ 55 comments… read them below or add one }
← Previous Comments
Excellent post!
So simple when you know how to do it, other posts have had me copying files, deleting this, symlinking that. For linux nohoper this helped no end
Thanks! Glad you found it helpful.
Thanks for the useful tip. Worked like a charm!
Thanks a lot. This helped
As simple as it must be! Great!
$ sudo service cron restart
is a nice one-line way to restart cron.
Thx Shaun, ya Ubuntu tells me that every time is use the init.d scripts, but I always forget. lol
Very nice!
Great tip!
Very well explained!
I’m still struggling with this.
My cronjobs are not running, and I believe it has something to do with the timezone. The machine was first built using AZ/Phoenix (GMT-7). I followed the above steps and made the system be GMT. After doing so, the following was returned:
root@tuxhyppx01:~# dpkg-reconfigure tzdata
Current default time zone: ‘Etc/GMT’
Local time is now: Mon Mar 11 17:08:59 GMT 2013.
Universal Time is now: Mon Mar 11 17:08:59 UTC 2013.
root@tuxhyppx01:~#
root@tuxhyppx01:~# date
Mon Mar 11 17:09:21 GMT 2013
root@tuxhyppx01:~#
I have a simple cronjob to test cron:
root@tuxhyppx01:~# crontab -l
16 17 * * * touch /tmp/file.txt
But nothing shows up in /tmp, and nothing in the logs.
Ideas?
Correction. Not sure why, but it just started working. I restarted cron– could that be it?
Please delete these 2 comments. All is good.
Thanks!
Could be, I know if you change the timezone of the system you have to restart cron for it to pick that change up. But as far as it not running at all, I’m not sure. I know on Ubuntu as soon as you start up the OS cron starts automatically. So it could be OS dependent.
Thanks buddy.
Man, this tip was awersome. Simple as it should be. Thanks
You should also restart a number of other processes, not just cron.
Syslog (or any of its cousins) is one, otherwise you’ll get wrong timestamps.
Also the databases (if any).
Nonetheless this is a very good snippet.
Grazie.
thanks.
Thank you for this great time-saving tip! (And for the service cron restart one in the comments) I always forget that so much is available in various dpkg-reconfigure commands that saves headaches!
I also found out you can use a symlink, like so:
ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime
source: http://askubuntu.com/a/323140
Thanks mate.
Brilliant, clear and straight to the point. Thanks a bunch.
Thank you so much for this instructions!
Thanks! I don’t know what I’d do without people like you making my life easy!!! Seriously! a BIG thanks!
What’s up really just began writing programs with Ruby so I am
just a bit of a newbie! But found your site very helpful and informative.
Thanks for your time!
Thanks for this – made life simple
Thaks..
You saved my time…
Obrigado!
Resolveu meu problema
Great article, simple and efficient.
Helped a lot.
Excellent job
Thank you dude!
You saved my time.
ありがとう!
Thank you for this. Such a simple task and so simply explained!!
BoL!!!
this is a nice tutorial. thanks for this tips……..
Very good, Thanks!!!
Excellent.
Solution in one line:
sudo dpkg-reconfigure tzdata && sudo service cron restart
thanks for the post.
Thanks for your post. It helped me reset time zone from Amazon Ec2 ubuntu instance which default time is in UTC. Thanks a lot, Nahm
Thank you for the great tutorial!
Thanks man!
You just made my day
Worked like a charm, I’ve done manual changes based on other guides but this was much easier using the select tool
great!!!
Thank you..
thanks
This was really useful! Good anticipation of the crontab restart, I would’ve had to spend another 15 mins troubleshooting if you hadn’t put that in.
Thanks!
thanks
Your comment about restarting cron is greatly helpful! Thank you
THANK YOU!!!!
Great Tip! Thanks a lot
Great article man!
Very helpful thanks. Didn’t know that dpkg-reconfigure command – sometimes it’s nice just to launch a GUI to make certain changes. And particularly liked the fact you recommend restarting cron
thank you so much for posting this. keep the great job up.
thanks for posting, save much of my time ! work perfect for me !
In 16.04 you use:
sudo timedatectl set-timezone Australia/Melbourne
sudo dpkg-reconfigure tzdata
Still works well for Melbourne or any other cities on 16.04.
Thank you )
It’s helpful thanks so much
Be careful when using timedatectl, it will let you set timezones with set-timezone that aren’t in the list-timezone output (for example: EST). The problem is that doing so may be wrong since you probably want EDT (daylight savings). This caused problems on “daylight savings weekend) when the system had EST as a timezone but the same time as Central Daylight Savings. I used ‘dpkg-reconfigure tzdata’ to fix the problem – it seems to be “smarter” than timedatectl.
{ 8 trackbacks }