Bug 4817 - NSDate to DateTime conversion wrong?
Summary: NSDate to DateTime conversion wrong?
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-05-02 06:25 UTC by Ruben Vermeersch
Modified: 2012-05-02 08:29 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
screenshot (40.34 KB, image/png)
2012-05-02 06:25 UTC, Ruben Vermeersch
Details
screenshot with full times (48.18 KB, image/png)
2012-05-02 07:12 UTC, Ruben Vermeersch
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:
Status:
RESOLVED INVALID

Description Ruben Vermeersch 2012-05-02 06:25:14 UTC
Created attachment 1790 [details]
screenshot

Have a look at the attached screenshot. The code that does this is roughly:

When the picker changes:

  DateTime someProp = picker.Date;
  label.Text = String.Format ("{0:D}", someProp);

Am I using this wrong or is this badly broken?
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-05-02 06:58:23 UTC
It's likely a timezone difference. Can you show the date(s) with timezone too?
Comment 2 Ruben Vermeersch 2012-05-02 07:12:21 UTC
Created attachment 1791 [details]
screenshot with full times

You are right, there's a two hour shift, probably because one of the types interprets the date as UTC and the other as local. Is there a recommended practice for dealing with NSDate/DateTime?
Comment 3 Ruben Vermeersch 2012-05-02 07:12:54 UTC
Added screenshot
Comment 4 Rolf Bjarne Kvinge [MSFT] 2012-05-02 07:44:02 UTC
They're actually the same date, just displayed differently.

Try this:

  DateTime someProp = picker.Date.ToLocalTime ();
  label.Text = String.Format ("{0:D}", someProp);
Comment 5 Ruben Vermeersch 2012-05-02 08:29:20 UTC
That was the fix, so it was a bug in my code. Thanks!