<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="static/bootstrap-datetimepicker-master/sample-in-bootstrap-v2/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="static/bootstrap-datetimepicker-master/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="static/bootstrap-datetimepicker-master/sample-in-bootstrap-v2/jquery/jquery-1.8.3.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="static/bootstrap-datetimepicker-master/sample-in-bootstrap-v2/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="static/bootstrap-datetimepicker-master/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript" src="static/bootstrap-datetimepicker-master/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
</style>
<script type="text/javascript">
$(document).ready(function() {
$(‘.form_date‘).datetimepicker({
format : ‘yyyy-mm-dd‘,
language : ‘zh-CN‘,
weekStart : 1,
todayBtn : 1,
autoclose : 1,
todayHighlight : 1,
startView : 2,
minView : 2,
forceParse : 0
});
var now = new Date();
var nowStr = formatDate(now);
$("#startDate").val(nowStr);
$("#endDate").val(nowStr);
});
function getDatetime() {
var startDate = $("#startDate").val();
var endDate = $("#endDate").val();
alert("startDate=" + startDate + ", endDate=" + endDate);
}
function formatDate(date) {
//var day = new Date();
var Year = 0;
var Month = 0;
var Day = 0;
var CurrentDate = "";
//初始化时间
//Year= day.getYear();//有火狐下2008年显示108的bug
Year = date.getFullYear();//ie火狐下都可
以
Month = date.getMonth() + 1;
Day = date.getDate();
//Hour = day.getHours();
// Minute = day.getMinutes();
// Second = day.getSeconds();
CurrentDate += Year + "-";
if (Month >= 10) {
CurrentDate += Month + "-";
} else {
CurrentDate += "0" + Month + "-";
}
if (Day >= 10) {
CurrentDate += Day;
} else {
CurrentDate += "0" + Day;
}
return CurrentDate;
}
</script>
</head>
<body>
<div style="width: 95%; height: 120px;">
<div class="control-group"
style="float: left; width: 180px; height: 60px;">
<label class="control-label">起始时间:</label>
<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">
<input id="startDate" size="16" type="text" style="width: 80px;"
value="" readonly> <span class="add-on"><i
class="icon-remove"></i></span> <span class="add-on"><i
class="icon-th"></i></span>
</div>
</div>
<div class="control-group"
style="float: left; width: 180px; height: 60px;">
<label class="control-label">结束时间:</label>
<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">
<input id="endDate" size="16" type="text" style="width: 80px;"
value="" readonly> <span class="add-on"><i
class="icon-remove"></i></span> <span class="add-on"><i
class="icon-th"></i></span>
</div>
</div>
<input type="button" value="时间">
</div>
</body>
<html>
本文出自 “8731262” 博客,请务必保留此出处http://8741262.blog.51cto.com/8731262/1566944
bootstrap datetimepicker 时间控件的使用
原文地址:http://8741262.blog.51cto.com/8731262/1566944