Last active
August 29, 2015 14:01
-
-
Save mattcanty/388f298067be478d7ddc to your computer and use it in GitHub Desktop.
Given a local british datetime, convert to UTC - take off an hour in summer
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
public static class DateTimeExtensions | |
{ | |
private static readonly TimeZoneInfo TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); | |
public static DateTime ConvertLocalBritishTimeToUtc(this DateTime dateTime) | |
{ | |
var isSummer = TimeZoneInfo.IsDaylightSavingTime(dateTime); | |
if (isSummer) | |
{ | |
dateTime = dateTime.AddHours(-1); | |
} | |
return new DateTime(dateTime.Ticks, DateTimeKind.Utc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated the to explicitly state that the outgoing datetimekind is UTC.