jstl fmt 标签给出的日期时间格式是什么?
What is the date time format given by jstl fmt tag?
要在 JSTL 中格式化日期和时间,我们可以使用 fmt
标记 here
我必须指定在其他前端工具(如数据表)中使用的日期格式。
我避免在 fmt 中使用任何特定格式,只是使用 type
或 dateStyle
等参数来获得某种格式的输出。但是 问题 是 datatables 需要知道日期 列的 格式才能正确排序这些字段。
当我使用像
这样的参数时
<fmt:formatDate type = "both" dateStyle = "long" timeStyle = "long" value = "${now}" />
输出为:
August 23, 2017 10:52:09 AM UTC
如何将此日期输出的格式指定为:
$.fn.dataTable.moment( 'MMMM dd, YYYY hh:mm:ss aa z' );
以获得准确的排序结果。
你应该使用:
$.fn.dataTable.moment( 'MMMM DD, YYYY hh:mm:ss A', false );
请注意它使用 forgiving mode,因为没有格式选项来表示日期的 UTC
部分。
这是完整的测试用例:
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/plug-ins/1.10.16/sorting/datetime-moment.js"></script>
</head>
<body>
<table id="example">
<thead>
<tr>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr><td>August 23, 2017 10:52:09 AM UTC</td></tr>
<tr><td>August 23, 2018 10:52:09 AM UTC</td></tr>
<tr><td>August 21, 2017 10:52:09 AM UTC</td></tr>
<tr><td>August 23, 2017 08:47:09 PM UTC</td></tr>
<tr><td>March 29, 2017 10:52:09 AM UTC</td></tr>
<tr><td>April 01, 2017 10:52:09 AM UTC</td></tr>
</tbody>
</table>
<script>
$(document).ready(function() {
$.fn.dataTable.moment( 'MMMM DD, YYYY hh:mm:ss A', false );
$('#example').DataTable();
} );
</script>
</body>
</html>
要在 JSTL 中格式化日期和时间,我们可以使用 fmt
标记 here
我必须指定在其他前端工具(如数据表)中使用的日期格式。
我避免在 fmt 中使用任何特定格式,只是使用 type
或 dateStyle
等参数来获得某种格式的输出。但是 问题 是 datatables 需要知道日期 列的 格式才能正确排序这些字段。
当我使用像
这样的参数时<fmt:formatDate type = "both" dateStyle = "long" timeStyle = "long" value = "${now}" />
输出为:
August 23, 2017 10:52:09 AM UTC
如何将此日期输出的格式指定为:
$.fn.dataTable.moment( 'MMMM dd, YYYY hh:mm:ss aa z' );
以获得准确的排序结果。
你应该使用:
$.fn.dataTable.moment( 'MMMM DD, YYYY hh:mm:ss A', false );
请注意它使用 forgiving mode,因为没有格式选项来表示日期的 UTC
部分。
这是完整的测试用例:
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/plug-ins/1.10.16/sorting/datetime-moment.js"></script>
</head>
<body>
<table id="example">
<thead>
<tr>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr><td>August 23, 2017 10:52:09 AM UTC</td></tr>
<tr><td>August 23, 2018 10:52:09 AM UTC</td></tr>
<tr><td>August 21, 2017 10:52:09 AM UTC</td></tr>
<tr><td>August 23, 2017 08:47:09 PM UTC</td></tr>
<tr><td>March 29, 2017 10:52:09 AM UTC</td></tr>
<tr><td>April 01, 2017 10:52:09 AM UTC</td></tr>
</tbody>
</table>
<script>
$(document).ready(function() {
$.fn.dataTable.moment( 'MMMM DD, YYYY hh:mm:ss A', false );
$('#example').DataTable();
} );
</script>
</body>
</html>