<< Back to Blog

30 JUNE 2021

.NET Core: Display DateTimeOffset.UtcNow in correct timezone with Daylight Savings applied

In this example assume the real time in the UK is 15:30 (we are in summer, Daylight Savings time). When DateTimeOffset.UtcNow is saved to the database it saves 14:30 (+00:00). When this time is displayed on a page to the user it will show 1hr earlier than it was.

To render it correctly with the correct time use the following code:

// C# code
// 14:30 (+00:00)
var myDateTimeOffset = exportRecord.CreatedDateTimeOffset;
var timeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
// 15:30 (+01:00)
return myDateTimeOffset.ToOffset(timeZone.GetUtcOffset(myDateTimeOffset));