what is the right way to parse JSON returned datetime field?
function updateChat(supplier_id, user_id, spantag) {
$.ajax({
type: "POST",
url: "AjaxService/ChatService.asmx/GetChatBySupplierID",
data: "{'supplier_id':'" + supplier_id + "', 'user_id':'" + user_id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var result = ($.parseJSON(response.d));
var str="";
for (var i = 0; i < result.length; i++) {
str += "[" + parseJSONDate(result[i].chat_create_dt) + " " + result[i].usr_fname + "] " + result[i].chat_text;
str += "";
}
$("#" + spantag).html(str);
setTimeout(function () {
updateChat(supplier_id,user_id, spantag)
}, 3500);
}
});
}
function parseJSONDate(jsonDate) {
var d = parseFloat(jsonDate.slice(6, 19) );
return new Date(d).format("MM/dd/yyyy hh:mm:ss tt");
}
Advertisement