I want send a datetime in JSON with string fromat from asp.net web service and I want javascript parse it like datetime and not like string.
So I ask is there a special format that I must use it to convert datetime to string and parse it in javascript as datetime?
In fact , I don't want touch javascript. I want javascript read the string and considerate it as DateTime.
-
Just to add: this could help you mattkruse.com/javascript/datesataniccrow– sataniccrow2012年10月31日 08:58:14 +00:00Commented Oct 31, 2012 at 8:58
-
If you want to get into details, you might want to read hanselman.com/blog/…Marius Balaban– Marius Balaban2012年10月31日 09:04:12 +00:00Commented Oct 31, 2012 at 9:04
3 Answers 3
Make sure your date strings conform rfc2822 and use javascript Date.parse method.
Alternatively, send your dates over as integer milliseconds and use Date constructors on the javascript side.
Comments
I used DateJS for a few projects using ASP.NET. The format will probably depend on your locale. I would looks at the data.js examples to make it work the way it would fit your specification and locale.
Comments
This is a piece of code I use to create a date from a .net JSON serialized DateTime object.
function formatJSONDate(jsonDate) {
var d = new Date((jsonDate.slice(6, -2)*1));
var day = d.getDate() * 1;
var month = (d.getMonth() * 1) +1;
var s = (day < 10 ? "0" : "") + day + "-" + (month < 10 ? "0" : "") + month + "-" + d.getFullYear();
return s;
}