How to set the timezone on Ubuntu Server

by Irish on March 21, 2012

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

$ date
Thu Mar 21 18:02:49 MST 2012

Or checking the timezone file at

$ more /etc/timezone
US/Arizona

So to change it just run

$ sudo dpkg-reconfigure tzdata

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 stop
$ /etc/init.d/cron start

{ 21 comments… read them below or add one }

Gary July 5, 2012 at 5:53 am

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

Reply

Irish July 5, 2012 at 10:00 am

Thanks! Glad you found it helpful.

Reply

Andrew July 10, 2012 at 8:19 am

Thanks for the useful tip. Worked like a charm!

Reply

sagar October 22, 2012 at 2:20 pm

Thanks a lot. This helped

Reply

Emerson December 5, 2012 at 11:01 am

As simple as it must be! Great!

Reply

Shaun January 22, 2013 at 11:25 am

$ sudo service cron restart
is a nice one-line way to restart cron.

Reply

Irish January 22, 2013 at 11:34 am

Thx Shaun, ya Ubuntu tells me that every time is use the init.d scripts, but I always forget. lol ;-)

Reply

Jairo February 15, 2013 at 8:15 pm

Great tip!
Very well explained!

Reply

Joseph March 11, 2013 at 10:19 am

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?

Reply

Joseph March 11, 2013 at 10:54 am

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!

Reply

Irish March 11, 2013 at 11:01 am

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.

Reply

Manish May 6, 2013 at 3:59 am

Thanks buddy.

Reply

Kalil Maciel June 14, 2013 at 7:33 am

Man, this tip was awersome. Simple as it should be. Thanks

Reply

Vincenzo Romano June 19, 2013 at 8:54 am

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.

Reply

Prasad July 27, 2013 at 4:53 am

thanks.

Reply

André Fischer November 15, 2013 at 3:08 am

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! :)

Reply

Julien January 29, 2014 at 7:53 pm

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

Reply

Leon January 31, 2014 at 12:50 am

Thanks mate.

Reply

Mau February 14, 2014 at 7:48 pm

Brilliant, clear and straight to the point. Thanks a bunch.

Reply

Christine Dorothy March 4, 2014 at 7:15 pm

Thank you so much for this instructions!

Reply

steve March 26, 2014 at 10:00 pm

Thanks! I don’t know what I’d do without people like you making my life easy!!! Seriously! a BIG thanks!

Reply

Leave a Comment

{ 4 trackbacks }

Previous post:

Next post: