Home > OS >  Blazor WASM DatePicker UTC
Blazor WASM DatePicker UTC

Time:03-29

I have a C# WASM Blazor Server-Side app.

When a user is selecting 29th March 2022 it's going into the database as 28th March 2022 at 23:00 hours.

Pushing it back 1 hour and into the previous day.

When i debug in VS with a local browser and step through the code this doesn't happen.

I feels like the client-side of the app is adjusting the time for live users.

We want everything in UTC but i cannot work out where i need to fix this.

The field in the DTO being sent the the business logic data is:

public DateTime? LatestPickupDate { get; set; }

and it's a datetime2(7) in the SQL Database

Can anyone offer any advice please?

Thanks

CodePudding user response:

You have to deal by yourself about the client timezone

some explanation here : https://www.meziantou.net/convert-datetime-to-user-s-time-zone-with-server-side-blazor.htm

keep in mind :

  • save the date in your database in UTC (retrieve the field as UTC like the example above)
  • when you render existing date from database at your user, do the inverse operation (adjust the utc date datetime to local with the client TimezoneOffset

CodePudding user response:

This turned out to be a problem with Safari. The date comes across correctly when the user is on Chrome

  • Related