billy jean
billy jean

Reputation: 1429

Ajax post javascript date as UTC OR server Time

I am trying to post a created date to an ASP.Net MVC controller without the date being modified by the serializer. I am looking for some kind of way to do this on the client.

The date is being constructed as follows:

var priceDate = new Date(name.split("-")[1], name.split("-")[0]-1, 1);

The date is valid and the problem is the serializer is adding the timezone offset which i don't want. The javascript date should be UTC but this doesn't seem possible.

This problem is expressed in different ways all over the place with all kinds of solutions that just seem way over the top. Is is possible to make a javascript date UTC or devoid of timezone information from the client?

Upvotes: 3

Views: 2957

Answers (1)

rnofenko
rnofenko

Reputation: 9533

There is toISOString() function which returns dates in standardized format and always does zero time zone.

Server accepts dates in local zone, so you need to do next date.ToUniversalTime().

So javascrript date.toISOString() equals to c# date.ToUniversalTime().

Upvotes: 1

Related Questions