无法使用Jquery datetimepicker格式化选定的日期时间

时间:2018-10-23 11:29:20

标签: jquery datetimepicker

Jquery datetimepicker中选择值时,我需要格式化日期和时间。我在下面解释我的代码。

<!doctype html>
<html>
    <head>
       <title>jQuery Datepicker UI Example - Demo Preview</title>
       <meta name="robots" content="noindex, nofollow"/>
       <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> 


       <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script> 
       <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet">
       <link rel="stylesheet" type="text/css" href="jquery.datetimepicker.min.css"/>
       <script src="jquery.datetimepicker.js"></script>

       <style type="text/css">
           .bootstrap-datetimepicker-widget.dropdown-menu.bottom {
               top: 26px !important;
           }
       </style>
    </head>

    <body>
        <div class="container">
            <div class="row">
                <div class="col-sm-12 top-buffer">
                    <h3>DatePicker Example</h3>
                    <input type="text" id="datetimepicker"/>
                </div>
            </div>
            <div class="bottom-buffer"></div>
       </div>

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

在这里,需要从压延机中选择值之后,输入字段的值格式应为dd-mm-yyyy hh:ii AM/PM or 23-10-2018 1.30 PM

请帮助我解决此问题。

1 个答案:

答案 0 :(得分:0)

尝试一下

 $(document).ready(function() {
        $('#datetimepicker').datetimepicker({
        format:'d.m.Y H:i:a',
        formatTime:'h:i:a'

        });
    });