Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 725
billy jean Avatar asked May 11 '26 15:05

billy jean


1 Answers

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().

like image 55
rnofenko Avatar answered May 14 '26 06:05

rnofenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!