Skip to content

Instantly share code, notes, and snippets.

@mattcanty
Last active August 29, 2015 14:01
Show Gist options
  • Save mattcanty/388f298067be478d7ddc to your computer and use it in GitHub Desktop.
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
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);
}
}
@mattcanty
Copy link
Author

Updated the to explicitly state that the outgoing datetimekind is UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment