【发布时间】:2013-06-30 14:29:39
【问题描述】:
是否可以使用jQuery UI Datepicker 格式化日期以显示小时、分钟和秒?
这是我目前的模型:
$(function() {
$('#datepicker').datepicker({ dateFormat: 'yyy-dd-mm HH:MM:ss' }).val();
});
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<title>snippet</title>
</head>
<body>
<input type="text" id="datepicker">
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script>
当我调用.datepicker({ dateFormat: 'yyy-dd-mm HH:MM:ss' }) 时,返回值为:
201313-07-03 HH:July:ss
这是JSFiddle。
【问题讨论】:
-
日期选择器只允许您选择日期,而不是时间,因此不支持格式化小时、分钟和秒。您可以自己附加 00:00:00。
-
var curTime = new Date()。您可以使用 moment 之类的库来随意格式化。
标签: javascript jquery datepicker jquery-ui-datepicker