Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Whenever I use DateTime.Now it always returns UTC time, which is not the timezone I live in. This also does NOT match the timezone on the emulator I'm using.
I live in CST timezone and the emulator accurately reflects that with the correct time in the upper-right corner. For example, the current time in CST timezone is 11:02 AM. But calling DateTime.Now returns 5:02 PM.
To make things more interesting new Java.Util.Date() returns the correct time. So I don't think this can be blamed on the device or emulator since the correct time is being returned by the Java version - it seems to be a bug in mono.
Here is actual output and results:
Log.Info("TEST", TimeZone.CurrentTimeZone.StandardName); // outputs CST
Log.Info("TEST", DateTime.Now.Hour.ToString()); // outputs 17
Log.Info("TEST", new Java.Util.Date().Hours.ToString()); // outputs 11
My emulator version and target platform is Android 2.1. I have no clue if this bug exists in other versions, but it should work in 2.1 regardless.
I could reproduce this only on an API Level 7 emulator. I tried the same logging on my ASUS Transformer (which runs Android 3.2) but I couldn't get that wrong result. DateTime.Now also showed local time. I also tried API Level 10 emulator, and it also worked fine.
From these results, it seems this is rather a bug in Android's underlying bionic libc on which our System.DateTime implementation depends. If that is the case, unfortunately there is no practical way to determine the actual local date in System.DateTime.
*** Bug 4227 has been marked as a duplicate of this bug. ***