Maximus Decimus
Maximus Decimus

Reputation: 5271

How to avoid time zone conversion when sending ISO dates to Web Api2 method

I have an ISO date in javascript like this 2017-04-29T00:00.000Z which I expect to be parsed as Date with time 12:00:00 AM in C# when I received the value in my web api2 method.

However, this value 2017-04-29T00:00.000Z is converted to my local time zone

[HttpPost]
public IHttpActionResult MyMethod(DateTime date)
{...}

This is my url send with Jquery .ajax "/api/Employee?date=" + date

How can I avoid my date to be transformed to current time zone when received? I am getting this value 2017-04-28 10:00 AM in C# when I send this value from $.ajax 2017-04-29T00:00.000Z

Upvotes: 1

Views: 480

Answers (1)

chris-crush-code
chris-crush-code

Reputation: 1149

Use DateTimeOffSet instead of DateTime.

Upvotes: 2

Related Questions