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

UPDATE July 2016
In the comments Dan mentions that in 16.04 you use something like:

$ sudo timedatectl set-timezone Australia/Melbourne

Need web application development, maintenance for your existing app, or a third party code review?

Velocity Labs can help.

Click here to get started!

{ 55 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

Vagner do Carmo December 25, 2014 at 2:36 pm

Very nice! :)

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

learn-programming-quickly.blogspot.co.uk April 4, 2014 at 12:08 pm

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!

Reply

Rob April 17, 2014 at 6:47 pm

Thanks for this – made life simple :-)

Reply

kanny April 29, 2014 at 4:41 am

Thaks..
You saved my time… :)

Reply

Wesley April 29, 2014 at 6:45 am

Obrigado!
Resolveu meu problema :)

Reply

Victor Kurauchi May 20, 2014 at 11:53 am

Great article, simple and efficient.

Helped a lot.

Reply

Jun May 21, 2014 at 8:39 am

Excellent job
:D

Reply

Maxwell June 30, 2014 at 4:17 am

Thank you dude!
You saved my time.
ありがとう!

Reply

Vachan Kumdule July 2, 2014 at 9:14 pm

Thank you for this. Such a simple task and so simply explained!!
BoL!!!

Reply

Sultan July 14, 2014 at 10:51 pm

this is a nice tutorial. thanks for this tips…….. :)

Reply

Reginaldo Gomes October 29, 2014 at 7:08 am

Very good, Thanks!!!

Reply

Ndiritu N November 15, 2014 at 7:48 am

Excellent.

Reply

Miguel November 16, 2014 at 2:59 pm

Solution in one line:

sudo dpkg-reconfigure tzdata && sudo service cron restart

thanks for the post.

Reply

Nahm November 19, 2014 at 1:35 pm

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

Reply

Erik December 14, 2014 at 11:36 pm

Thank you for the great tutorial! ;)

Reply

Nihan Dip January 1, 2015 at 9:52 am

Thanks man!
You just made my day

Reply

josh January 27, 2015 at 6:24 am

Worked like a charm, I’ve done manual changes based on other guides but this was much easier using the select tool :)

Reply

sergio belli March 18, 2015 at 8:34 am

great!!!

Reply

Onur April 21, 2015 at 2:05 pm

Thank you..

Reply

Diego Ferreira da Silva April 23, 2015 at 6:55 pm

thanks

Reply

liang April 26, 2015 at 4:52 pm

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!

Reply

worked June 14, 2015 at 4:03 am

thanks

Reply

Jon B November 23, 2015 at 3:59 pm

Your comment about restarting cron is greatly helpful! Thank you

Reply

al December 8, 2015 at 12:42 pm

THANK YOU!!!!

Reply

Davi Crystal December 10, 2015 at 6:09 am

Great Tip! Thanks a lot

Reply

Viny Machado February 14, 2016 at 3:47 pm

Great article man!

Reply

BG February 28, 2016 at 3:05 pm

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

Reply

Mohamed Bile Super April 24, 2016 at 2:04 am

thank you so much for posting this. keep the great job up.

Reply

zhibinw June 13, 2016 at 7:52 pm

thanks for posting, save much of my time ! work perfect for me !

Reply

Dan July 19, 2016 at 5:42 pm

In 16.04 you use:

sudo timedatectl set-timezone Australia/Melbourne

Reply

Francis Kim March 19, 2017 at 5:09 pm

sudo dpkg-reconfigure tzdata
Still works well for Melbourne or any other cities on 16.04.

Reply

Sylvain June 24, 2017 at 3:47 pm

Thank you :o )

Reply

Tausif March 28, 2018 at 9:48 pm

It’s helpful thanks so much :)

Reply

Leroy Tennison March 11, 2019 at 8:38 am

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.

Reply

Leave a Comment

{ 8 trackbacks }

Previous post:

Next post: