-1

I'm trying to pull the hours and minutes out of a Microsoft JSON string. I've gone through several articles, the most recent one being: How do I format a Microsoft JSON date? to no avail. When I try to follow the example code provided.

The alert won't fire. Not sure what I'm doing wrong or missing. The pertinent code is here:

$.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('');
    //This is my code based off stack overflow article, and it breaks 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);
});

data.beginDelayDateTime has /Date(1531958520000)/ in it and that value ("/Date(1531958520000)/") displays in the alert with no problems.

BeginnerOne
  • 71
  • 1
  • 9

1 Answers1

1

The problem was solved by correcting a typographical error. As epascarello pointed out BeginDelayDateTime != beginDelayDateTime. By correcting the misspelling, the issue was resolved an the Microsoft JSON date string is being parsed correctly. Many thanks to all who contributed their help.

BeginnerOne
  • 71
  • 1
  • 9