10/30/2025 6:55:36 PM

Dates seems to always be a pain in the ass. That is why it is always best to store dates in UTC format. If you do that, EVERY DATE YOU SEE IN THE DATABASE IS UTC. Now, of course there are exceptions but this is a nice simple rule.

However, if you are hanging out over on the east coast and loading up these dates from a database using Entity Framework, you might get some unexpected behaviors in .NET. And it gets stranger still when you deploy your code to an AWS zone over on the west coast.

To deal with this, you can use the code below in your DbContext class to convert all .NET DateTime properties to DateTime.Kind = UTC. This ensures that every time you look at the date in the Db or in .NET, you are viewing a UTC date.

And tomorrow you can worry about the absolute shittiness of dates in Javascript.

protected override void OnModelCreating(ModelBuilder modelBuilder) { //base.OnModelCreating(modelBuilder); var dateTimeUtcConverter = new Converters.DateTimeUtcConverter(); foreach (var entityType in modelBuilder.Model.GetEntityTypes()) { foreach (var property in entityType.GetProperties()) { if (property.ClrType == typeof(DateTime) || property.ClrType == typeof(DateTime?)) { property.SetValueConverter(dateTimeUtcConverter); } } } base.OnModelCreating(modelBuilder); }