Update the tzdata library in time to avoid time processing problems across time zones

introduction

Today, when verifying the time point of an African country transmitted by a front-end, the local debugging passed the normal verification, but after deploying to the server, the verification failed, which feels very strange. So I checked the source code of a key function used and found that when loading the time zone, the data in the Time Zone Database (refer to the previous article "IANA Time Zone Database and ZONEINFO Detailed Explanation") will be used. Taking Golang as an example, load it as follows Time zone functions use data from the Time Zone Database:

 time.LoadLocation("Africa/Cairo")

In Linux system, the location of Time Zone Database is /usr/share/zoneinfo.

What is tzdata?

The full name of the tzdata software package is time zone and daylight-saving time (DST) data, which is installed for each Linux system to read the data in the Time Zone Database. The Time Zone Database, tz or tzinfo for short, is a set of codes and data representing the time history of various places on the earth, currently maintained by IANA.

tzdata may have different implementations on different platforms, usually under the zoneinfo folder, which contains information files for all time zones. On Linux systems, this folder is usually located at /usr/share/zoneinfo.

By using tzdata, applications and operating systems can automatically switch time zones based on your location and selected settings. This is critical for international businesses and global applications that span different time zones.

update tzdata

Because the Time Zone Database will be updated as the time zone of the country or region on the earth changes, the Time Zone Database on the server should also be kept updated to the latest version.

Take Debian/Ubuntu as an example, first set it as non-interactive, and install it according to the default method:

export DEBIAN_FRONTEND=noninteractive 

update download source

apt-get update

Install or update tzdata

apt-get install -y tzdata 

By the way, let me introduce how to set the time zone. To set the time zone to East Eighth District, execute the following command:

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Guess you like

Origin blog.csdn.net/luduoyuan/article/details/131216447