将自定义日期格式添加到JSP html代码中



<td>${item.actionDate}</td>接收格式为2019-11-17(yyyy/mm/dd(的日期。我想将此格式编辑为dd/mm/yyyy。我发现我可以通过使用以下内容为这个td元素提供格式。

<script type="text/javascript">
$(document).ready(function() {
$('#serial_no_date_format').datepicker({
format: 'dd/mm/yyyy'
});
})
</script>

我知道上面的代码片段是正确的,因为它在我的代码的其他部分中起作用。但是,我无法将此日期格式传递给id为reference的td.item.actionDate元素。

我的整体低于

<div class="tab-pane fade active in" id="tab_1_1">
<div class="row">
<div class="col-md-12">
<table class="table table-striped table-bordered table-hover order-column">
<thead>
<tr>
<th>Sevkiyat No</th>
<th>Operator</th>
<th>İşlem Tarihi</th>
<th>İşlem</th>
<th>Lokasyon</th>
</tr>
</thead>
<tbody>
<c:forEach items="${shipmentTransferHistoryList}" var="item">
<tr>
<td>${item.shipmentDetailId}</td>
<td>${item.operator}</td>
<td>${item.actionDate} id="serial_no_date_format"</td>
<td>${item.shipmentStatus.alias}</td>
<td>${item.actionLocation}</td>
</tr>
</c:forEach>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('#serial_no_date_format').datepicker({
format: 'dd/mm/yyyy'
});
})
</script>
</div>
</div>
</div>

我怎样才能做到这一点?

您的id应该设置在标记内。

<td>${item.actionDate} id="serial_no_date_format"</td>

更改到此

<td id="serial_no_date_format">${item.actionDate} </td>

请注意,您可能会遇到重复id的问题,因此如果可能的话,请将其更改为类。

编辑

我想这会解决你的问题。

var date = $('#serial_no_date_format').datepicker({format: 'dd/mm/yyyy'}).val();
$('#serial_no_date_format').val(date);

最新更新