0

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.

asked Oct 31, 2012 at 8:53
2

3 Answers 3

1

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.

answered Oct 31, 2012 at 8:55

Comments

0

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.

answered Oct 31, 2012 at 8:57

Comments

0

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;
}
answered Oct 31, 2012 at 9:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.