如何格式化Microsoft JSON日期?

家住魔仙堡 提交于 2020-08-14 19:17:51

问题:

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: 基本上,我得到的字符串看起来像这样:

/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插件,但没有成功。

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

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. 该解决方案从回调方法中获取了我的对象,并使用日期格式库在页面上正确显示了日期。


解决方案:

参考一: https://stackoom.com/question/rgm/如何格式化Microsoft-JSON日期
参考二: https://oldbug.net/q/rgm/How-do-I-format-a-Microsoft-JSON-date
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!