This article is a mirror article of machine translation, please click here to jump to the original article.

View: 20568|Reply: 0

[.NET Core] DateTime time in .Net Core is inconsistent with Windows time in Linux Docker

[Copy link]
Posted on 11/12/2019 4:38:30 PM | | | |
Recently wrote a .net core project, deployed to CentOS and run on docker, found that DateTime.Now got the time inconsistent with Windows (scheduled task, 8 hours late), and the local time was correctly obtained in Windows, while the time obtained in Linxu CentOS's Docker environment was 8 hours less. Check the local time with the Linxu command, the local time is correct, but the .net core is still 8 hours less than 8 hours when running in Docker. Guessing that it might be a time zone problem, I found a library of NodaTime to get the time of the unified time zone, which is the same as the time obtained on the Docker environment of Linxu CentOS.




nuget install:



Package expansion method:

The time obtained in the program can be maintained in the following methods to maintain uniformity between Windows and Linux:


Also, a tutorial on container setup time is attached:

Docker time inconsistencies, container time time zone setting
https://www.itsvse.com/thread-8865-1-1.html
(Source: Architect_Programmer)



(End)






Previous:ASP.NET Core MVC memory cache usage tutorial
Next:Linux Tip: tee displays and redirects content
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com