I've been struggling to extract the hours and minutes from a Microsoft JSON string. Despite reading through numerous articles, including How do I format a Microsoft JSON date?, I have not been successful. Even when attempting to implement the example code provided.
However, the alert function does not seem to work. I am unsure of what mistake I may be making or what crucial detail I might be overlooking. The relevant portion of the code is as follows:
$.ajax({
type: "GET",
url: "/TrainActivity/GetDelayDataForEditing/" + "?delayId=" + delId,
dataType: 'json',
//data: delId,
success: function(data) {
//data = JSON.stringify(data);
//$("#myDivID").text(JSON.stringify(data));
//var delayId = delId;
modal.find('');
//The following code snippet is based on the Stack Overflow article but it seems to disrupt the alert
var date = new Date(parseInt(data.beginDelayDateTime.substr(6)));
//var date = data.beginDelayDateTime.substr(6);
//var date = new Date(parseInt(jsonDate.substr(6)));
//this date is okay
//var date = new Date();
var unparsedDate = moment(data.beginDelayDateTime);
var parsedDate = new Date(unparsedDate);
var hours = parsedDate.getHours;
var minutes = parsedDate.getMinutes;
var timeToDisplay = hours + ":" + minutes;
//var timeToDisplay = JSON.stringify(hours) + ":" + JSON.stringify(minutes);
alert("Success " +
//"\ntest date: " + date +
"\nunparsed date: " + unparsedDate +
"\nParsed date: " + parsedDate +
"\nDisplay time: " + timeToDisplay +
"\nbegin Delay time: " + data.BeginDelayDateTime
);
//$('#delays-grid').data('kendoGrid').dataSource.read();
//$("#delayAddModal").modal("hide");
},
error: function() {
alert("error in Delay Edit");
}
});
//modal.find(".modal-body").text("Edit the Delay at " + name + " with id " + delId);
modal.find(".modal-footer #delayEditButton").data("guid", delId);
});
The value stored in data.beginDelayDateTime is "/Date(1531958520000)/" and this value displays in the alert without any issues.