Use EF Core to easily save dates as UTC & show in local time
roundthecode.com·1d
Abseil Time
Preview
Report Post

Having trouble with time zones in your ASP.NET Core application?

If you use Entity Framework Core you can easily save dates as UTC in the database and then convert them back to your local time zone in your ASP.NET Core application.

This is particularly crucial if your application spans multiple time zones.

Introducing ValueConverters

A ValueConverter allows you to translate an entity’s value to a provider like a SQL Server database and then translate it back to the model for an ASP.NET Core application.

This is perfect for what we want as we can convert a time to UTC when saving it in the database and then convert it back to the local time zone when using it in the application.

How to create a ValueConverter

To make this work you need to create a new class, import th…

Similar Posts

Loading similar posts...