-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: DateTime.Now from .NET 6 will return UTC time, not local time in Ubuntu #63194
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
I checked the area label and I think it should belong to area-Microsoft.CSharp since it is about CSharp function, but unfortunately I don't have permission to add the label. |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsDescriptionWe upgraded our system from .NET 5 to .NET 6. After that, all our time showing on the UI side has been changed from local time to UTC time. Since our system is running on Ubuntu 20.04 Linux server, from our tests, we found that all DateTime.Now call will return a UTC time, not local time. We think this should be a bug. We tested .NET 5 before and DateTime.Now works well. Our current solution is to read timezone from Linux system and to convert UTC time to local time. Reproduction StepsExpected behaviorDateTime.Now should return local time Actual behaviorDateTime.Now returns the UTC time Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
Related: #60469 - Please read that issue and see if that fixes/explains your problem, or please report with the information the diagnostic steps listed there provide. That aside -
|
The ticket #60469 shows the similar issue (user using .NET 6 testing version), and tarekgh said the problem has solved in .NET 6.0 official version, but I'm using the .NET 6.0.1 version. I got the same issue again, so I don't think this issue has been solved in .NET 6.0.1 version. DateTime.Now.ToString("G") still returns the UTC time.
|
Based on the comment from #60469, I ran the following code and the output following:
Output: |
Does not compute. Can you add Also, what is the output of the question in this comment? |
What are you running on "locally"? A devcontainer? I think there was an issue about the current local time being mapped into the container. If so, that still makes sense, because a remote server would still be set to UTC/not mapped. |
Our system is running in a Ubuntu Docker container in a Ubuntu Host, but we mapped local time from host to container. |
Ah, I thought I'd remembered this: #62545 I'd say "use the recommendation at the end of the thread", but barring exceptional circumstances you probably shouldn't be setting the timezone of the container at all. |
Thanks Clockwork-Muse! I'll do more tests. |
No, the That aside, why do you care? By your own admission this isn't going to be part of your final deployment, so you seem to be doing a bunch of work that you're not going to keep. |
Sorry I didn't explain our application very clearly. |
From our tests, this issue should be the docker Ubuntu container local time issue that the local time in the container always be set as UTC time. We didn't find why to be set UTC time always yet, but we believe it's not because of .NET 6 version since the local time in the host (Ubuntu) works well. My solution for this issue is to get timezone from /etc/timezone file, and then calculate the local time via UTC time. Finally, replace all DateTime.Now by our function. Based on this, I recommend to close this bug ticket. Thanks so much for your help! |
Description
We upgraded our system from .NET 5 to .NET 6. After that, all our time showing on the UI side has been changed from local time to UTC time. Since our system is running on Ubuntu 20.04 Linux server, from our tests, we found that all DateTime.Now call will return a UTC time, not local time. We think this should be a bug.
We tested .NET 5 before and DateTime.Now works well.
Our current solution is to read timezone from Linux system and to convert UTC time to local time.
Reproduction Steps
Expected behavior
DateTime.Now should return local time
Actual behavior
DateTime.Now returns the UTC time
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: