background Using the node-schedule scheduled task library, I wrote a script to automatically send emails at 7 am every day, and the email will get the date of the day. question The email was received at 3pm instead of 7am. I guess it was due to the time zone setting. Problem analysis and solutions After investigation, it was found that the node-schedule library does not support the selection of time zone, so it is sent according to the global standard time UTC by default. The time we usually pass in is CST, the Shanghai time zone in China, which is eight hours different. let j = schedule.scheduleJob('name',"0 7 * * *",'Asia/Shanghai', function () { console.log("Execute task"); getAllDataAndSendMail(); }); New Problem After changing the time, a new problem occurred. The time obtained in the email was yesterday's time, not today's time. Problem analysis and solutions After thinking about it, there are two places in the code to get the time, one is the time to send the email passed in by the scheduled task library, and the other is to get the current time in the script let today = new Date() Because I have printed today's log, check the log docker logs -f [containerID] # today:2021-11-12T23:00:00.106Z It was found that the email sent at 7 am was received today at 23:00 the previous day, which is also 8 hours different. Use the following command to enter the docker container to check the time $ docker exec -it [containerID] sh # After entering the container, the front will become# # Enter date to view the time date # Sat Nov 13 05:05:31 UTC 2021 It is indeed UTC global standard time, which means that the time of sending the email has indeed been changed back, but the time obtained when the code is executed is the current global standard time. docker cp /etc/localtime [containerID]:/etc/ Check the time in the container again as above and find that it has been changed back to CST. There should be no problem. This is the end of this article about the docker container time zone error problem. For more related docker time zone error content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Bootstrap 3.0 study notes grid system principle
>>: MySQL database index order by sorting detailed explanation
Background: I'm working on asset reporting re...
Preface Recently, when I was building a project, ...
Table of contents 1. Create components using func...
If this is the first time you install MySQL on yo...
React multiple ways to get the value of the input...
I recently took over a small program project, and...
This article example shares the specific code of ...
Preface In the previous article, we mainly learne...
the difference: 1. InnoDB supports transactions, ...
<br />Related articles: 9 practical suggesti...
Table of contents 1. Introduction 2. On-demand at...
After minimizing the installation of Python8, I i...
So-called talent (left brain and right brain) Tha...
Preface 1. Debounce: After a high-frequency event...
This is a cheating scheme for voting websites wit...