I have following unit test which fails
[Fact]
public void Convert_to_and_from_unix_timestamp()
{
// Arrange
var timestamp = 1636579063;
var date = DateTimeOffset.FromUnixTimeSeconds(timestamp).DateTime;
// Act
var unixTimeSeconds = ((DateTimeOffset)date).ToUnixTimeSeconds();
// Assert
Assert.Equal(expected: timestamp, actual: unixTimeSeconds);
// result
// Expected: 1636579063 // 10/11/2021 21:17:43
// Actual: 1636575463 // 10/11/2021 20:17:43
}
The new (actual) Unix timestamp is minus one hour. My machine timezone is UTC+1. Does it mean, that DateTimeOffset is automatically setting up my timezone (UTC+1) into the datetime and when converting back into the timestamp the DateTimeOffset is removing the UTC+1 so there is one hour decrease? How can I manage timezone in both ways?