首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataTables从数据库呈现错误的DateTime值

DataTables从数据库呈现错误的DateTime值
EN

Stack Overflow用户
提问于 2019-05-06 19:38:30
回答 1查看 817关注 0票数 1

我在asp.net mvc项目中使用datatable插件,而绑定数据则呈现错误的日期时间值

数据库中的实际日期时间值是05-5月19日2:43:33 PM,运行显示的值是/Date(1557060213477)/

它显示数据库中存在的日期时间值的预期结果。

这是我的模型

代码语言:javascript
复制
 public int Id { get; set; }
 [Required]
 public string Name { get; set; }
 Display(Name ="Upload File")]
 public string FileUrl { get; set; }
 public DateTime AddedOn { get; set; }

这是我的看法

代码语言:javascript
复制
<table id="DDR" class="table table-striped table-bordered dt-responsive nowrap">
    <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>
            <th>Uploaded File</th>
            <th>Uploaded At</th>
            <th>Edit</th>
            <th>Delete</th>
        </tr>
    </thead>
</table>
@section scripts {
    <link href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
    <script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
    <script>
        $(document).ready(function () {
            debugger;
            $("#DDR").DataTable({
                "ajax": {
                    "url": "/DomesticDocRepositories/GetData",
                    "type": "GET",
                    "datatype": "json"
                },
                "columns": [
                    {
                        "data": "Id",
                        render: function (data, type) {
                            return '<a href="/DomesticDocRepositories/Details/' + data + '">'+data+"</a>";
                        }
                    },

                    { "data": "Name" },
                    {
                        data: "FileUrl",
                        render: function (data, type) {
                            return "<a href='/DomesticFiles/" + data + " 'target='_blank''>" + data + "</a>";
                        }
                    },
                    {
                        "data": "AddedOn",
                        render: function (data, type) {
                            return '<span "title='+ data +"'>" + data +"</span>";
                        }
                    },
                    {
                        "render": function (data, type, full, meta) { return '<a class="btn btn-info" href="/DomesticDocRepositories/Edit/' + full.Id + '">Edit</a>'; }
                    },
                    {
                        data: null, render: function (data, type, row) {
                            return '<a class="btn btn-danger" href="/DomesticDocRepositories/Delete/' + row.Id + '">Delete</a>';
                        }
                    },
                ]
            });
        });
    </script>
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-06 19:44:22

使用moment.js for datetimes (文档).in您的呈现,您应该在呈现中使用:

代码语言:javascript
复制
{
    render: function (data, type, row) {//data
        return moment(row.AddedOn ).format('DD/MM/YYYY hh:mm:ss');//or another format you wantt.
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56011365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档