garrus_j
❔ DateTime help with NodaTime
public static DateTimeOffset ConvertCETToUTC(this DateTime cetTime)
{
// var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
//
// bool isDST = dateTimeCET.IsDaylightSavingTime();
// DateTimeOffset dateTimeOffsetUTC = TimeZoneInfo.ConvertTimeToUtc(dateTimeCET, timeZoneInfo);
var cetInstant = Instant.FromDateTimeUtc(cetTime.ToUniversalTime());
var cetZone = DateTimeZoneProviders.Tzdb["Europe/Berlin"];
var cetZoned = new ZonedDateTime(cetInstant, cetZone);
var utcZoned = cetZoned.ToInstant().InUtc();
DateTime utcTime = utcZoned.ToDateTimeUtc();
return utcTime;
}
9 replies