Datetimepiker 时间选择

Datetimepiker是一个BootStrap的组件,用于实现时间的精确选择。

引用css和js文件

<link rel="stylesheet" href="{% static 'web/datetimepicker/bootstrapdatetimepicker.min.css' %}">
<script src="{% static 'web/datetimepicker/bootstrapdatetimepicker.min.js' %}"></script>    <script src="{% static 'web/datetimepicker/bootstrapdatetimepicker.zh-CN.js' %}"></script

html标签

<input id='i1' />

应用到标签

$('#i1,#i2').datetimepicker({    
	language: "zh-CN",    
	minView: "hour",    
	sideBySide: true,    
	format: 'yyyy-mm-dd hh:ii',    
	bootcssVer: 3, 
	startDate: new Date(),    
	autoclose: true 
})

扩展: js中对时间的格式化

Date.prototype.Format = function (fmt) { //author: meizz            
	var o = {
		"M+": this.getMonth() + 1,                
		"d+": this.getDate(), //෭                
		"h+": this.getHours(), //ੜ෸                
		"m+": this.getMinutes(), //ړ                
		"s+": this.getSeconds(), //ᑁ                
		"q+": Math.floor((this.getMonth() + 3) / 3), //ਊଶ                	  "S": this.getMilliseconds() //ྺᑁ            
		};            
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));            			for (var k in o)                
			if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			return fmt;
		};
原文地址:https://www.cnblogs.com/yzm1017/p/13571012.html