【问题标题】:Jquery Data tables Date format [duplicate]Jquery数据表日期格式[重复]
【发布时间】:2020-01-15 15:27:40
【问题描述】:

我试图在我的数据表中提取日期,但由于某种原因数据格式不正确。我正在从存储过程中获取数据。

原文:

/Date(1575612000000)/

预期输出:

01-15-2020

代码示例:

 $(document).ready(function () {
    var mesa = $('.datatable').DataTable({
        filename: "LocationCodes",
        responsive: true,
        "bAutoWidth": false, // toggle this depending on how wide you want the table
        "ajax": {
            "url": "/controller/sp",
            "type": "GET",
            "datatype": "json"
        },
        "deferRender": true,
        "responsive": true,
        dom: 'Bfrtip',
        "bSort": false,
        buttons: [
            'excel', 'print'
        ],
        "columns": [
            { "data": "FileName" },
            { "data": "ProjectName" },
            { "data": "RecordInsertTime" }
        ]

谢谢, 民哈尔

【问题讨论】:

  • 这不是数据表问题。 Date 的格式是这样的,因为这就是 ASP.Net MVC 以 JSON 格式返回日期的方式(非常烦人)。请参阅我标记的副本以了解如何处理它们
  • @RoryMcCrossan 感谢您为我指明正确的方向。

标签: javascript jquery datatables jquery-datatables-editor


【解决方案1】:

这是你想要的吗?

var d = new Date(1575612000000);
let month=d.getMonth()+1  // 12
let date=d.getDate()     // 6
let year=d.getFullYear() 
console.log(`${date}-${month}-${year}`)

【讨论】:

  • 这与提出的问题完全无关。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-20
  • 2020-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多