Skip to content

Instantly share code, notes, and snippets.

@trinnguyen
Last active April 5, 2024 16:14
Show Gist options
  • Save trinnguyen/e8d743d1403cf90b7d3b to your computer and use it in GitHub Desktop.
Save trinnguyen/e8d743d1403cf90b7d3b to your computer and use it in GitHub Desktop.
Xamarin.iOS convert between NSDate and DateTime , default LocalTime
using Foundation;
using System;
using System.Collections.Generic;
using System.Text;
namespace UICode.iOS
{
public static class Extensions
{
public static NSDate DateTimeToNSDate(this DateTime date)
{
if (date.Kind == DateTimeKind.Unspecified)
date = DateTime.SpecifyKind(date, DateTimeKind.Local);
return (NSDate)date;
}
public static DateTime NSDateToDateTime(this NSDate date)
{
return ((DateTime)date).ToLocalTime();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment