Last active
April 5, 2024 16:14
-
-
Save trinnguyen/e8d743d1403cf90b7d3b to your computer and use it in GitHub Desktop.
Xamarin.iOS convert between NSDate and DateTime , default LocalTime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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