Given a DateTimeOffset
and a TimeZoneInfo
, how can I convert that specific point in time instant to start of day in the given time zone?
Example:
public static DateTimeOffset AtMidnightInTimeZone(this DateTimeOffset date, TimeZoneInfo timeZone)
{
return ?;
}
[Fact]
public void AtMidnightInTimeZone()
{
// Arrange
var dateTime = DateTimeOffset.Parse("2020-06-28T13:00:00+00:00");
var timeZone = TZConvert.GetTimeZoneInfo("Europe/Paris");
// Act
var date = dateTime.AtMidnightInTimeZone(timeZone);
// Assert
Assert.Equal(DateTimeOffset.Parse("2020-06-28T00:00:00+02:00"), date);
}