TL;DR — Resumen Rápido
Configure la zona horaria del sistema en Ubuntu Server con timedatectl: liste zonas disponibles, cambie la zona predeterminada, verifique sincronización NTP y persista la configuración.
Nota: Este artículo fue publicado originalmente en 2013. Algunos pasos, comandos o versiones de software pueden haber cambiado. Consulta la documentación actual de Ubuntu para la información más reciente.
Requisitos Previos
Antes de comenzar, asegúrate de tener:
- A system running Ubuntu (desktop or server edition)
- Terminal access with sudo privileges
- Basic familiarity with Linux command line
How to: Set the (https://en.wikipedia.org/wiki/Time_zone “Time zone”) on (https://ubuntu.com “Ubuntu (operating system)”)
If you are using a VM hosted with a public cloud provider you probably have realized that they generally are deployed using (https://en.wikipedia.org/wiki/Coordinated_Universal_Time “Coordinated Universal Time”) as the default timezone. In (https://www.microsoft.com/WINDOWS “Windows”) I was very familiar modifying that but now that I have deployed an Ubuntu server I wasn’t sure where to begin. Every time I executed a php script on the terminal I got a warning that I should not rely on the server timezone (UTC) but set the right one on my php.ini file. I ended up doing that but I realized all the logs, etc are still based on the UTC timezone so I decided it was time to set my timezone on my Ubuntu server.
It turns out it is rather simple, just a few commands and considerations and you are set and done!
I. Verify the current settings and time using date (there is also a timezone file in /etc/timezone):
date Wed Dec 10 04:10:03 UTC 2013
or as mentioned you should also check what is your current time zone (in my case, I was originally in UTC)
more /etc/timezone Etc/UTC
II. To change the timezone you need to execute sudo dpkg-reconfigure tzdata.
This will launch an interface for you to select the timezone from a number of options. If you have installed Ubuntu Server before it is the same screen as when you install your server. When you are done you´ll receive the following output on the terminal:
sudo dpkg-reconfigure tzdata Current default time zone: ‘America/Mexico_City’ Local time is now: Tue Dec 09 22:12:45 CST 2013. (https://en.wikipedia.org/wiki/Universal_Time “Universal Time”) is now: Wed Dec 10 04:12:45 UTC 2013.
as you can see this is rather simple.
III. Don’t forget to restart cron
Otherwise it won’t pick up the timezone change. If possible I recommend a whole server restart just to make sure everything picks up the change: sudo service cron restart