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...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help