Bug 28584 - Xamarin.iOS: Converting from DateTime to NSDate
Summary: Xamarin.iOS: Converting from DateTime to NSDate
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.8.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-03-31 07:43 UTC by andy
Modified: 2015-03-31 07:57 UTC (History)
2 users (show)

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

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:

Description andy 2015-03-31 07:43:49 UTC
Dear Xamarin Team.

Since the Daylight-Saving-Time in CEST (Central European Summer Time) is active (29.03.2015) the Conversion from DateTime to NSDate gives me a wrong Time.


var nsDateNow = NSDate.Now; // nsDateNow is 11:37 GMT +00 => Correct
var nsDateNowConverted = DateTime.Now.DateTimeToNSDate (); // nsDateNowConverted is 12:38 GMT +00 => Incorrect

My DateTimeToNSDate Method looks like following:

public static NSDate DateTimeToNSDate(this DateTime date)
			DateTime reference = TimeZone.CurrentTimeZone.ToLocalTime(
				new DateTime(2001, 1, 1, 0, 0, 0) );
			return NSDate.FromTimeIntervalSinceReferenceDate(
				(date - reference).TotalSeconds);
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-03-31 07:57:49 UTC
Use the DateTimeToNSDate logic from our documentation [1] instead:

	public static NSDate DateTimeToNSDate(this DateTime date)
	    if (date.Kind == DateTimeKind.Unspecified)
	        date = DateTime.SpecifyKind (date, /* DateTimeKind.Local or DateTimeKind.Utc, this depends on each app */)
	    return (NSDate) date;

[1] http://developer.xamarin.com/guides/cross-platform/macios/unified/