參考連接:http://www.bootcss.com/p/bootstrap-datetimepicker/javascript
一、官網以及很詳細的說明了如何使用,這裏結合一下本身的使用來寫下。css
下載解壓縮包之後,能夠看到有兩個實例,能夠打開看看,分別是sample in bootstrap v二、sample in bootstrap v3。
html
二、sample in bootstrap v2實例的代碼以下所示。java
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> 6 <link href="../css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen"> 7 </head> 8 9 <body> 10 <div class="container"> 11 <form action="" class="form-horizontal"> 12 <fieldset> 13 <legend>Test</legend> 14 <div class="control-group"> 15 <label class="control-label">DateTime Picking</label> 16 <div class="controls input-append date form_datetime" data-date="1979-09-16T05:25:07Z" data-date-format="dd MM yyyy - HH:ii p" data-link-field="dtp_input1"> 17 <input size="16" type="text" value="" readonly> 18 <span class="add-on"><i class="icon-remove"></i></span> 19 <span class="add-on"><i class="icon-th"></i></span> 20 </div> 21 <input type="hidden" id="dtp_input1" value="" /><br/> 22 </div> 23 <div class="control-group"> 24 <label class="control-label">Date Picking</label> 25 <div class="controls input-append date form_date" data-date="" data-date-format="dd MM yyyy" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd"> 26 <input size="16" type="text" value="" readonly> 27 <span class="add-on"><i class="icon-remove"></i></span> 28 <span class="add-on"><i class="icon-th"></i></span> 29 </div> 30 <input type="hidden" id="dtp_input2" value="" /><br/> 31 </div> 32 <div class="control-group"> 33 <label class="control-label">Time Picking</label> 34 <div class="controls input-append date form_time" data-date="" data-date-format="hh:ii" data-link-field="dtp_input3" data-link-format="hh:ii"> 35 <input size="16" type="text" value="" readonly> 36 <span class="add-on"><i class="icon-remove"></i></span> 37 <span class="add-on"><i class="icon-th"></i></span> 38 </div> 39 <input type="hidden" id="dtp_input3" value="" /><br/> 40 </div> 41 </fieldset> 42 </form> 43 </div> 44 45 <script type="text/javascript" src="./jquery/jquery-1.8.3.min.js" charset="UTF-8"></script> 46 <script type="text/javascript" src="./bootstrap/js/bootstrap.min.js"></script> 47 <script type="text/javascript" src="../js/bootstrap-datetimepicker.js" charset="UTF-8"></script> 48 <script type="text/javascript" src="../js/locales/bootstrap-datetimepicker.fr.js" charset="UTF-8"></script> 49 <script type="text/javascript"> 50 $('.form_datetime').datetimepicker({ 51 //language: 'fr', 52 weekStart: 1, 53 todayBtn: 1, 54 autoclose: 1, 55 todayHighlight: 1, 56 startView: 2, 57 forceParse: 0, 58 showMeridian: 1 59 }); 60 $('.form_date').datetimepicker({ 61 language: 'fr', 62 weekStart: 1, 63 todayBtn: 1, 64 autoclose: 1, 65 todayHighlight: 1, 66 startView: 2, 67 minView: 2, 68 forceParse: 0 69 }); 70 $('.form_time').datetimepicker({ 71 language: 'fr', 72 weekStart: 1, 73 todayBtn: 1, 74 autoclose: 1, 75 todayHighlight: 1, 76 startView: 1, 77 minView: 0, 78 maxView: 1, 79 forceParse: 0 80 }); 81 </script> 82 83 </body> 84 </html>
效果以下所示:jquery
三、你會發現,案例裏面的都是英文,因此我這裏修改成了中文。他這個年月日時分秒能夠本身決定,是隻用年月日,時分秒,仍是年月日時分秒等等本身能夠進行需求選擇。
bootstrap
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> 6 <link href="../css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen"> 7 </head> 8 9 <body> 10 <div class="container"> 11 <form action="" class="form-horizontal"> 12 <fieldset> 13 <legend>Test</legend> 14 <div class="control-group"> 15 <label class="control-label">DateTime Picking</label> 16 <div class="controls input-append date form_datetime" data-date="1979-09-16T05:25:07Z" data-date-format="dd MM yyyy - HH:ii p" data-link-field="dtp_input1"> 17 <input size="16" type="text" value="" readonly> 18 <span class="add-on"><i class="icon-remove"></i></span> 19 <span class="add-on"><i class="icon-th"></i></span> 20 </div> 21 <input type="hidden" id="dtp_input1" value="" /><br/> 22 </div> 23 <div class="control-group"> 24 <label class="control-label">Date Picking</label> 25 <div class="controls input-append date form_date" data-date="" data-date-format="dd MM yyyy" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd"> 26 <input size="16" type="text" value="" readonly> 27 <span class="add-on"><i class="icon-remove"></i></span> 28 <span class="add-on"><i class="icon-th"></i></span> 29 </div> 30 <input type="hidden" id="dtp_input2" value="" /><br/> 31 </div> 32 <div class="control-group"> 33 <label class="control-label">Time Picking</label> 34 <div class="controls input-append date form_time" data-date="" data-date-format="hh:ii" data-link-field="dtp_input3" data-link-format="hh:ii"> 35 <input size="16" type="text" value="" readonly> 36 <span class="add-on"><i class="icon-remove"></i></span> 37 <span class="add-on"><i class="icon-th"></i></span> 38 </div> 39 <input type="hidden" id="dtp_input3" value="" /><br/> 40 </div> 41 </fieldset> 42 </form> 43 </div> 44 45 <script type="text/javascript" src="./jquery/jquery-1.8.3.min.js" charset="UTF-8"></script> 46 <script type="text/javascript" src="./bootstrap/js/bootstrap.min.js"></script> 47 <script type="text/javascript" src="../js/bootstrap-datetimepicker.js" charset="UTF-8"></script> 48 <!--中文引用--> 49 <script type="text/javascript" src="../js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script> 50 <!--英文引用--> 51 <!--<script type="text/javascript" src="../js/locales/bootstrap-datetimepicker.fr.js" charset="UTF-8"></script>--> 52 <script type="text/javascript"> 53 $('.form_datetime').datetimepicker({ 54 //language: 'fr', 55 language : 'zh-CN', 56 //format : 'yyyy-mm-dd hh:ii:ss',//日期格式。能夠將日期格式,定成年月日時分秒。 57 format : 'yyyy-mm-dd hh:00:00',//日期格式。能夠將日期格式,定成年月日時,分秒爲0。 58 weekStart: 1, 59 todayBtn: 1, 60 autoclose: 1, 61 todayHighlight: 1, 62 startView: 2, 63 forceParse: 0, 64 showMeridian: 1 65 }); 66 $('.form_date').datetimepicker({ 67 language : 'zh-CN', 68 //format : 'yyyy-mm-dd hh:ii:ss',//日期格式 69 //language: 'fr', 70 weekStart: 1, 71 todayBtn: 1, 72 autoclose: 1, 73 todayHighlight: 1, 74 startView: 2, 75 minView: 2, 76 forceParse: 0 77 }); 78 $('.form_time').datetimepicker({ 79 //language: 'fr', 80 language : 'zh-CN', 81 //format : 'yyyy-mm-dd hh:ii:ss',//日期格式 82 weekStart: 1, 83 todayBtn: 1, 84 autoclose: 1, 85 todayHighlight: 1, 86 startView: 1, 87 minView: 0, 88 maxView: 1, 89 forceParse: 0 90 }); 91 </script> 92 93 </body> 94 </html>
效果以下所示:這樣一搞,就能夠顯示中文了,日期格式能夠本身定義。更多的使用能夠查看api。api
待續......app