I have a date in JavaScript and its value is coming like this
Fri Apr 01 2011 05:00:00 GMT+0530 (India Standard Time) {}
Now what is the best way to convert the date to .NET date . Note that my client side users can be anwyehere around the world. I will have the date from there now my need is to convert it to the .NET date. can you help me ?
Possible duplicate of the question answered here: Javascript date to C# via Ajax
If you want local time, like you are showing in your question the following would do it.
DateTime.ParseExact(dateString.Substring(0,24),
"ddd MMM d yyyy HH:mm:ss",
CultureInfo.InvariantCulture);
If you are looking for GMT time, doing a dateObject.toUTCString()
in Javascript in the browser before you send it to the server, would do it.
Convert JavaScript into UTCString from Client side:
var testDate = new Date().toUTCString();
Parse it from C# code (you can fetch js date through webservice call).
DateTime date = DateTime.Parse(testDate);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With