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.

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.

Sign up to request clarification or add additional context in comments.

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.

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;
}

Comments

Your Answer

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.