“This is the 8th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”

Hi, family, I’m bug bug, here I go again. Let’s talk about something today. OK, let’s continue with the Ubuntu series. Listen and learn! Good cut?

A: Environmental description

Environment: Ubuntu20.04

2: preface

Run the project accidentally in the execution of new SQL, any time field involved, write time and Beijing time difference 8, it is very outrageous. But obviously the Ubuntu system shows the same time as Windows. Next, I ran a godcode test!

Write a section of the main function to get the time to try, as I expected; Run the results situation console.

Boy, how hard am I working, at 2:00 in the morning! There must be something wrong, but I remember resetting the system time after installing Ubuntu. What can I do? After consulting relevant information, I found that it was like this:

The reason for this is that Windows and Ubuntu view hardware time (displayed by the BOIS on the motherboard) differently by default;

On Linux computers, there are two times, one is

The hardware of time

(The time recorded in BIOS, called hwclock), another is

Operating system time

(osclock);

If you think again, the time obtained by The Java program is GMT (Greenwich Mean time (time in time zone 0)), while the system is Beijing time, it should be GMT+8, which is just 8 hours different. Therefore, it is directly inferred that there is a time zone difference in the Ubuntu hardware time.

Let’s first query the system clock and time Settings; Use the following command directly

timedatectl
Copy the code

Sure enough, the time zone defaults back to the US time zone, no wonder!

Here, it is necessary to popularise the three concepts of time acquired above:

  • Coordinated Universal Time
  • GMT stands for Greenwich Mean Time
  • RTC time, or real-time clock, is the hardware time of a computer

Windows and Linux view system hardware time differently by default:

Linux clocks are divided into System clocks and hardware (RTC) clocks. Linux treats hardware time as UTC, and system time is converted from UTC. For example, if the Beijing time is GMT+8, the system displays the hardware time +8.

Windows treats the system hardware (RTC) time as the local time. That is, the system time is the same as the RTC displayed in the BIOS.

That know the reason to know how to solve, just need to change the time zone into a domestic can!

Set the time zone

timedatectl set-timezone "Asia/Shanghai"
Copy the code

Check whether kangkang time zone is set successfully:

The time zone has been set successfully; Let’s run main again;

And you’re done! The hardware time obtained by new Date is the same as the system time. You learned?

In summary, this is the dry goods teaching, if not enough to eat, bug bacteria think again ~

Three, hot article recommendation

  1. How to install Ubuntu20.04 on Windows 10
  2. How to install IDEA and IDEA stomp guide on Ubuntu20.04
  3. How to install maven and environment variable configuration on Ubuntu20.04

. .

For more articles on Ubuntu, check out Bug Bug’s Ubuntu Zero-based Teaching column, which will continue to be updated. Teach you how to understand Ubuntu! I use my hands to make your dreams come true.

———————————————————————————————-

If you think this article is helpful to you, please don’t forget to click on the bottom left corner of the article to light it up!! If I were you, don’t hesitate to go straight to my favorites to eat ashes! No matter later use not on, first eat ash again, ha ha ha ha ha ha ha belch ~~

———————————————————————————————-​

If this article has been helpful, please put your thumb in the bottom left corner of the article. (# ^. ^ #);

If you like the articles shared by Bug bug, please send bug bug a note! The danjun ‘ᴗ, you guys will have a cameo appearance with you.

If you have any questions about this article, please leave a comment below or join the group [Group number: 708072830].

In view of limited personal experience, all views and technical research points, if you have any objection, please directly reply to participate in the discussion (no offensive comments, thank you);

Copyright notice: This article is the blogger’s original article, reprint please attach the original source link and this article statement, all rights reserved, piracy will investigate! (* ^ del ^ *).