Skip to content

Instantly share code, notes, and snippets.

View Jimiwillz's full-sized avatar

James Williams Jimiwillz

  • Fraedom
  • Auckland
View GitHub Profile
@YARG
YARG / gist:6ab928f53127e78bcf10
Last active May 28, 2018 19:42
C#/Xamarin iOS - Converts a UTC DateTime to the device local Time Zone as System.DateTime. Also includes functions to convert iOS native date times to System.DateTime and back again.
/// <summary>
/// Converts a UTC datestamp to the local timezone
/// </summary>
/// <returns>The UTC to local time zone.</returns>
/// <param name="dateTimeUtc">Date time UTC.</param>
public DateTime ConvertUTCToLocalTimeZone (DateTime dateTimeUtc)
{
NSTimeZone sourceTimeZone = new NSTimeZone ("UTC");
NSTimeZone destinationTimeZone = NSTimeZone.LocalTimeZone;
NSDate sourceDate = DateTimeToNativeDate (dateTimeUtc);
@YARG
YARG / gist:2b9a50abc9c3524d40fc
Last active January 15, 2020 14:15
C#/Xamarin Android - Converts a UTC DateTime to the device local Time Zone as System.DateTime. Also includes functions to convert Android native date times to System.DateTime and back again.
/// <summary>
/// Converts a UTC datestamp to the local timezone
/// </summary>
/// <returns>The UTC to local time zone.</returns>
/// <param name="dateTimeUtc">Date time UTC.</param>
public DateTime ConvertUTCToLocalTimeZone(DateTime dateTimeUtc) {
// get the UTC/GMT Time Zone
Java.Util.TimeZone utcGmtTimeZone = Java.Util.TimeZone.GetTimeZone ("UTC");