为了账号安全,请及时绑定邮箱和手机立即绑定

来自猫鼬日期戳的 JS 日期格式

来自猫鼬日期戳的 JS 日期格式

忽然笑 2021-11-18 20:37:50
我知道类似的问题已被问过很多次,但没有答案是我正在寻找的。我的代码如下所示:        <table id="dtBasicExample" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">            <thead>                <tr>                <th class="th-sm">Date Requested                </th>                <th class="th-sm">Client                </th>                <th class="th-sm">Waybill                </th>                <th class="th-sm">From                </th>                <th class="th-sm">To                </th>                <th class="th-sm">Service                </th>                <th class="th-sm">Supplier                </th>                <th class="th-sm">kg                </th>                <th class="th-sm">Supplier                </th>                <th class="th-sm">VAT                </th>                <th class="th-sm">Total                </th>                <th class="th-sm">Client                </th>                <th class="th-sm">VAT                </th>                <th class="th-sm">Total                </th>                <th class="th-sm">Profit                </th>                <th class="th-sm">Status                </th>                <th class="th-sm">Modify                </th>                </tr>            </thead>专注于这条线:<td><%-x.createdAt%></td>在网上查看是这样的:2019 年 9 月 27 日星期五 17:38:08 GMT+0200(南非标准时间)我希望它看起来像什么:2019 年 9 月 27 日使用moment.js 这可能吗?我试过的: 在顶部:<script src="/js/moment.js"></script>然后(用于测试目的的硬编码日期)<td><script>moment('1977-08-20 14:29:00 UTC').format('dd MMM YYYY')</script>   </td>
查看完整描述

1 回答

?
摇曳的蔷薇

TA贡献1793条经验 获得超6个赞

我实际上对 JS 很陌生,我花了几分钟才弄明白,但实际上非常简单..


<td><%-x.createdAt%></td>

改为


<td class="formattedDate"><%-x.createdAt%></td>

并在添加以下内容之前的底部:


<script src="/js/jquery-3.3.1.js"></script>


<script>

$(document).ready(function () {

    var x = document.getElementsByClassName('formattedDate');

    for (i = 0; i < x.length; i++) {

        x[i].innerHTML = moment(x[i].innerHTML).format('DD MMM YYYY');

    }

});

</script> 

希望这可以帮助


查看完整回答
反对 回复 2021-11-18
  • 1 回答
  • 0 关注
  • 135 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信