View the dates with the correct timezone.

UtcNow and JSON

In the server side code we always use UtcNow and store all the dates in the UTC timezones.

The web server can be anywhere in the world and the operating system can use any kind of timezone or locale, using UTC we don’t have to care about the timezone.

Angular date pipe use the browser local timezone by default. That is what we normally want for our applications: users want to read time in the same way they read their watches.

The only problem is that Newtonsoft serializer default configuration sends the dates without any timezone information.

Change the serializer settings in mvc configuration in Startup.ConfigureServices

  .AddJsonOptions(options => {
      options.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc;

Look at how the dates are sent in json before and after the change



Note that there is the Z of the timezone and now Angular can correctly read the date.