Created DateTime TimeZone saving issue

I’m running Umbraco in an Azure AppService with the timezone set to AWST. When saving a document, the Created datetime seems to be saved as localtime (AWST) instead of UTC, so when I view the document, the Created datetime is showing as AWST+8h. Is there some configuration I can apply to fix this? Thank you.

Hi there!

I have noticed this as well. There is this old bug report on GitHub which addresses the issue, but it seems to have been closed because there was no activity on it:

As far as I know, this same issue is still relevant on Umbraco 13, but I haven’t tested it in Umbraco 15.

Although I don’t think we can do much about the way this date is displayed in the backoffice, if you need to use these dates in your code, you may apply a timezone correction this way:

public static DateTime MakeUmbracoDateUtc(this DateTime umbracoDate, TimeZoneInfo sourceTimeZone)
{
    var localDateTime = new DateTime(umbracoDate.Ticks, DateTimeKind.Unspecified);
    return TimeZoneInfo.ConvertTimeToUtc(localDateTime, sourceTimeZone);
}

For your source timezone you’ll want to get the AWST timezone so that you get a proper UTC date.

I didn’t even know this was possible.

This is not specific to Umbraco, but I strongly recommend using UTC for production environments. Time Zones are hard and can be the source of a lot of bugs (like this one) so removing them from the equation wherever possible is a good idea.

My site is targeted for users in a specific timezone, so it’s convenient being able to use local time in certain places in the backend, but I thought Umbraco would be saving dates to the DB in UTC which doesn’t seem to be the case as system time (in AWST) is being used instead. This is the last resort if there are no other solutions. Thank you.

I have also ran into this issue:

1 Like

Yeah, sorry, I should have been more diligent - the version I’m using is v15 (latest).

In Umbraco 17, this is fixed in the sense that dates are always saved in UTC. You can read about it in the latest blog:

Consistent Handling of Dates

Umbraco stores quite a number of system dates within its database, including creation and update dates for entities, dates related to user actions, and for the setup of scheduled publishing. There is currently an inconsistency here, though, as we sometimes use server time and in others coordinated universal time (UTC). Storage is also of an unspecified datetime, without timezone information, meaning it’s difficult to be sure as to exactly what date and time is represented - particularly if an application has moved between servers running different clocks.

For Umbraco 17, we have addressed this so that we consistently persist UTC dates and expose these from the management API, delivery API, and in Razor template rendering.

2 Likes