1

I'm on an angular app with .net core 3.1 backend. I use a material datepicker. When I pick up a date I can see in the console it looks like

Wed Feb 10 2021 00:00:00 GMT+0100

However, when it arrives in my web api controller, the value has changed. It's now in utc and therefor, it's set to the previous day

StartDate.ToString()
//"09/02/2021 23:00:00"
StartDate.Kind
//Utc

I understand it's something to do with gmt vs utc. But I'm not sure about the best way to fix it. Any advice?

Julien
  • 101
  • 2
  • 12

1 Answers1

3

I assume you use DateTime type in your DTO models on server side. DateTime does not contain any info about timezone, so I assume that json serealizer converts it into UTC if the target type cannot keep timezone info (if the target type is DateTime).

Please try to use DateTimeOffset type instead. Let me know if it helps.

Amir Arbabian
  • 3,419
  • 1
  • 6
  • 12