如何格式化Microsoft JSON日期? - How do I format a Microsoft JSON date?

问题:

I'm taking my first crack at Ajax with jQuery. 我正在使用jQuery在Ajax上进行首次尝试。 I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. 我正在将数据存储到页面上,可是为Date数据类型返回的JSON数据遇到了一些麻烦。 Basically, I'm getting a string back that looks like this: 基本上,我获得的字符串看起来像这样: json

/Date(1224043200000)/

From someone totally new to JSON - How do I format this to a short date format? 从彻底不熟悉JSON的人-如何将其格式化为短日期格式? Should this be handled somewhere in the jQuery code? 是否应该在jQuery代码中的某个地方处理? I've tried the jQuery.UI.datepicker plugin using $.datepicker.formatDate() without any success. 我已经尝试使用$.datepicker.formatDate()尝试使用jQuery.UI.datepicker插件,但没有成功。 this

FYI: Here's the solution I came up with using a combination of the answers here: 仅供参考:这是我结合如下答案使用的解决方案: spa

function getMismatch(id) {
  $.getJSON("Main.aspx?Callback=GetMismatch",
    { MismatchId: id },

    function (result) {
      $("#AuthMerchId").text(result.AuthorizationMerchantId);
      $("#SttlMerchId").text(result.SettlementMerchantId);
      $("#CreateDate").text(formatJSONDate(Date(result.AppendDts)));
      $("#ExpireDate").text(formatJSONDate(Date(result.ExpiresDts)));
      $("#LastUpdate").text(formatJSONDate(Date(result.LastUpdateDts)));
      $("#LastUpdatedBy").text(result.LastUpdateNt);
      $("#ProcessIn").text(result.ProcessIn);
    }
  );

  return false;
}

function formatJSONDate(jsonDate) {
  var newDate = dateFormat(jsonDate, "mm/dd/yyyy");
  return newDate;
}

This solution got my object from the callback method and displayed the dates on the page properly using the date format library. 该解决方案从回调方法中获取了个人对象,并使用日期格式库在页面上正确显示了日期。 .net


解决方案:

参考一: https://stackoom.com/question/rgm/如何格式化Microsoft-JSON日期
参考二: https://oldbug.net/q/rgm/How-do-I-format-a-Microsoft-JSON-date
相关文章
相关标签/搜索