忽然笑
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>在網(wǎng)上查看是這樣的:2019 年 9 月 27 日星期五 17:38:08 GMT+0200(南非標(biāo)準(zhǔn)時(shí)間)我希望它看起來像什么:2019 年 9 月 27 日使用moment.js 這可能嗎?我試過的: 在頂部:<script src="/js/moment.js"></script>然后(用于測(cè)試目的的硬編碼日期)<td><script>moment('1977-08-20 14:29:00 UTC').format('dd MMM YYYY')</script> </td>
1 回答

搖曳的薔薇
TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊
我實(shí)際上對(duì) JS 很陌生,我花了幾分鐘才弄明白,但實(shí)際上非常簡(jiǎn)單..
<td><%-x.createdAt%></td>
改為
<td class="formattedDate"><%-x.createdAt%></td>
并在添加以下內(nèi)容之前的底部:
<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>
希望這可以幫助
添加回答
舉報(bào)
0/150
提交
取消