-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
DateTime.Now
on Linux has wrong timezone
#60469
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. |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsDescriptionWhen use Reproduction StepsUsing Ubuntu 20.04:
However the code: DateTime localNow = DateTime.Now;
DateTime utcNow = DateTime.UtcNow;
Console.WriteLine($"localNow: {localNow}, {localNow.Kind}, utcNow: {utcNow}, {utcNow.Kind}");
Console.WriteLine($"TimeZoneInfo.Local: {TimeZoneInfo.Local}"); Produces output:
Expected behavior
Actual behavior
Regression?No response Known WorkaroundsNo response ConfigurationUsing dotnet sdk 6.0.100-rc.1.21463.6 on Linux (Ubuntu 20.04).
Other informationNo response
|
I cannot reproduce it with .NET 6 rc2, could you try again with rc2? |
Hi @hez2010, thanks for the reply. I also tried on dotnet 5.0.401 and 6.0.100-rc.2.21505.57, still has this issue. |
@ivan7wl
Since .NET reads time zone information from |
Hi, please checkout the UPDATE in Other Information. |
Hi @hez2010 , I cannot reproduce this issue anymore, after I run the |
I don't know why but things are get more and more complicated, I can now reproduce this on 6.0.100-rc.2.21505.57, but cannot reproduce on 5.0.401.
|
Could you please try to create a simple Console application from scratch using Console.WriteLine($"{RuntimeInformation.OSDescription}");
Console.WriteLine($"{RuntimeInformation.FrameworkDescription}");
Console.WriteLine($".... Invariant: {typeof(object).Assembly.GetType("System.Globalization.GlobalizationMode").GetProperty("Invariant", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null)} ....");
Console.WriteLine($"{TimeZoneInfo.Local.Id}"); please run this console app against .NET 6.0 and 5.0. if you still see the issue, please share to us the file |
Then I changed the timezone:
|
Yes the |
ok, thanks. This issue should be fixed in the release build already. If you are interested to try it, you may try installing the 6.0 release build from https://github.com/dotnet/installer. I am closing the issue but feel free to send any question if you have any. Thanks for your report. |
@tarekgh Thanks for your reply, I tried .NET 6.0.0-rtm.21515.9 and it works. However |
Is that a known issue? What is the output? @agocke |
Hi @danmoseley , maybe this is an unreleased version, the output is:
|
I re-opened this since I was seeing unexpected behavior. After a code review, I saw that my code was wrong. Oops! Working on some samples at dotnet/dotnet-docker#4414 |
Description
When use
DateTime.Now
on my Linux machine, dotnet assume the timezone is UTC.Reproduction Steps
Using Ubuntu 20.04:
However the code:
Produces output:
Expected behavior
DateTime.Now
has the proper local time.Actual behavior
DateTime.Now
always equal to UTC time, no matter what the system timezone is.Regression?
No response
Known Workarounds
No response
Configuration
Using dotnet sdk 6.0.100-rc.1.21463.6 on Linux (Ubuntu 20.04).
Other information
UPDATE:I found this issue may relate to RTC settings:But this is weird, when I usetimedatectl set-local-rtc 0 --adjust-system-clock
to set it back, this issue cannot be reproduced anymore.The text was updated successfully, but these errors were encountered: