使用jQuery UI Datepicker时如何格式化日期,小时,分钟和秒?

问题描述:

是否可以使用 jQuery UI Datepicker 格式化日期以显示小时,分钟和秒?

Is it possible to format a date with jQuery UI Datepicker as to show hours, minutes and seconds?

这是我当前的模型:

$(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 '})返回值为:

When I call .datepicker({ dateFormat: 'yyy-dd-mm HH:MM:ss' }) the returned value is:


201313-07-03 HH:July:ss

201313-07-03 HH:July:ss

这是 JSFiddle

$("#datepicker").datepicker("option", "dateFormat", "yy-mm-dd ");

对于时间选择器,你应该将时间戳添加到Datepicker,它将使用一个等效命令格式化。

For the time picker, you should add timepicker to Datepicker, and it would be formatted with one equivalent command.

编辑

使用这个扩展jQuery UI Datepicker。您可以同时选择日期和时间。

Use this one that extend jQuery UI Datepicker. You can pick up both date and time.

http://trentrichardson.com / examples / timepicker /