Linux system modification system time and time zone

Source: Internet
Author: User
Tags local time

Reference from: https://jingyan.baidu.com/article/fa4125acb7328628ac70920e.html

Today we have a problem,
My MySQL table has a field that is, Send_acode_timestamp, the default value is: Current_timestamp.
The resulting value is in the format: 2018-06-12 13:17:56
There is also a field, Create_time, with the value format: 1529906080

But after today's inspection, I found it wrong.
The Create_time value is correct, but the send_acode_timestamp is not correct.

The Create_time value is the PHP code that was added with time (), and Send_acode_timestamp, which is related to the database.
So I checked the server system time of a database, and sure enough the problem is here.
It would be nice to modify the system time.

Anyone who has installed a Linux system may have the experience that the machine has the right time to install the Windows system, but when the Linux system is installed, the system time is incorrect, even if the time zone is selected correctly. This is because UTC is used to install the system, so what is UTC, that is, UTC is the time of the 0 time zone, the international standard, and China is in the utc+8 time zone.

Another time is local time, and Windows uses local time. Therefore, when installing a Linux system, do not choose to use UTC.

Linux Date Tzselect

Modify the system time.

There are two Linux system clocks, one is the hardware clock, that is, the BIOS time, which is the time we see in CMOS setup, and the other is the system clock, which is the kernel time of the Linux system. When Linux starts, the system kernel reads the hardware clock settings, and the system clock is independent of the hardware. Sometimes we find that the system clock is inconsistent with the hardware clock, so we need to perform time synchronization and share the command usage of time settings and clock synchronization.

The date command sets the dates to June 18, 2018

----Date-s 06/18/18

Set the time to 14 points, 20 minutes, 50 seconds

----Date-s 14:20:50

Set the time to June 18, 2018 14:16 30 seconds (MMDDHHMMYYYY.SS)

----Date 0618141618.30

Hwclock/clock command to view, set hardware time

Viewing the system hardware clock

Hwclock--show or

Clock--show

Set Hardware time

Hwclock--set--date= "06/18/18 14:55" (Month/day/year: minutes: seconds) or # clock--set--date= "06/18/18 14:55" (Month/day/year: minutes: seconds)

Synchronous system and hardware clock.

You can see that the hardware and system clocks differ by half an hour. can be synchronized using hwclock or clock,

The hardware clock is synchronized with the system clock:

# hwclock --hctosys 或者 # clock--hctosys HC represents the hardware time, SYS represents the system time, i.e. the system clock is synchronized with the hardware clock

system clock and Hardware clock synchronization:

# hwclock --systohc或者# clock --systohc
Synchronize the hardware clock with the system clock

Time zone settings:
To start setting the time zone, refer to the information on the Internet, using the Tzselect command, and found that the Tzselect command only tells the way to set the time zone, not really to modify/etc/sysconfig/clock this file. In other words, the tzselect command simply tells us to select the time zone by setting the TZ environment variable, and then add the variable to the. profile file. Here's a quick introduction to how to set the time zone using the Tzselect command, and how to set the time zone by modifying the/etc/sysconfig/clock configuration file.

? Tzselect:
Execute the tzselect command--Select asia--> Select china--> Select East China-beijing, Guangdong, Shanghai, etc--> and enter 1. Process such as:

After executing the tzselect command to select the time zone, the time zone is not changed, but the command finally prompts you to execute tz= ' Asia/shanghai '; Export TZ and add this line of command to the. Profile, then exit and log back in. Refer to the results as seen in the Date command, and the final time zone is shown as CST, China Standard Time.

Modify the configuration file to modify the time zone
1, modify the/etc/sysconfig/clock??? ???
Zone=asia/shanghai
2, Rm/etc/localtime
3. Link to Shanghai time zone file???????
? ln-sf/usr/share/zoneinfo/asia/shanghai/etc/localtime
After performing the above procedure, restart the machine to see that the time zone has changed.

Linux system modification system time and time zone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.