用JQuery Ajax返回一個Entity的Json數據時,如果Entity的屬性中有日期格式,那返回來的是一串字符串,如下圖所示:

JQuery返回Json日期格式的問題 

在網上找了很久也沒有找到一個好的解決方案,最後自己寫一個javascrip Function 特此記錄,以備後用:

調用前的圖像問題:

JQuery返回Json日期格式的問題 

1 function ChangeDateFormat(cellval)
2 {
3     var date = new Date(parseInt(cellval.replace("/Date(""").replace(")/"""), 10));
4     var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
5     var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
6     return date.getFullYear() + "-" + month + "-" + currentDate;
7 }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2022-02-16
  • 2021-12-22
  • 2021-07-04
  • 2022-12-23
猜你喜欢
  • 2021-12-22
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-01-13
相关资源
相似解决方案