2

From the ajax, I am receiving datetime as:

Screen Shot

Not sure now to parse it with jquery to "dd/MM/yyyy"

1

3 Answers 3

4

Since you posted your question in the tag, you could embed your approach in a jQuery function:

//returns a Date() object in dd/MM/yyyy $.formattedDate = function(dateToFormat) { var dateObject = new Date(dateToFormat); var day = dateObject.getDate(); var month = dateObject.getMonth() + 1; var year = dateObject.getFullYear(); day = day < 10 ? "0" + day : day; month = month < 10 ? "0" + month : month; var formattedDate = day + "/" + month + "/" + year; return formattedDate; }; //usage: var formattedDate = $.formattedDate(someDateObjectToFormat); 

This will work with both valid Date objects and the result you get back from your JSON string:

var randomDate = new Date("2015-09-30"); var epochTime = new Date(1263183045000); var jsonResult = "\/Date(1263183045000)\/"; //outputs "30/09/2015" alert($.formattedDate(randomDate)); //both below output "11/01/2010" alert($.formattedDate(epochTime)); alert($.formattedDate(new Date(parseInt(jsonResult.substr(6))))); 

Aside: the format of the date portion in your result is in Unix time—aka Epoch time—i.e. the number of seconds elapsed after 01/01/1970 00:00:00 UTC.

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

Comments

1

Got Solved with following code

 var date = new Date(parseInt(data.UPDATED_ON.substr(6))); alert(date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear()); 

Comments

1

My solution:

// convert MVC datetime (e.g. "\/Date(628318530718)\/") into JavaScript Date value = new Date(parseInt(value.replace("/Date(", "").replace(")/",""), 10)); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.