bootstrap 3 datetimepicker 开始日期提前 2 周
bootstrap 3 datetimepicker start date 2 weeks ahead
我想提前 2 周启动我的日期时间选择器....这是我的代码
<div class="container">
<div class="row">
<div class='col-sm-3'>
<input type='text' class="form-control" id='datetimepicker4' />
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker4').datetimepicker();
});
</script>
试试这个代码....
<div class="container">
<div class="row">
<div class='col-sm-3'>
<input type='text' class="form-control" id='datetimepicker4' />
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker4').datetimepicker({
defaultDate: '+7d'
});
});
</script>
假设您正在使用这个库:https://eonasdan.github.io/bootstrap-datetimepicker/
$(function () {
$('#datetimepicker9').datetimepicker({
viewMode: 'years',
defaultDate: formatDate(getDateTwoWeeksFromNow())
});
});
function getDateTwoWeeksFromNow() {
new Date(+new Date + 12096e5);
}
function formatDate(date) {
return [date.getDate(), date.getMonth(),date.getFullYear()].join('/')
}
给你一个解决方案https://jsfiddle.net/0Ltv25o8/5532/
$('#datetimepicker2').datetimepicker({
defaultDate: moment().add('days', 14)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/src/js/bootstrap-datetimepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<div class="row">
<div class="col-md-12">
<input type="text" class="form-control" id="datetimepicker2" />
</div>
</div>
我用moment加了14天
您也可以添加周而不是天
$('#datetimepicker2').datetimepicker({
defaultDate: moment().add('weeks', 2)
});
用于禁用过去的日期
$('#datetimepicker2').datetimepicker({
minDate: moment().add('days', 14)
});
希望对您有所帮助。
请参考 jsFiddle,因为库 link.
导致代码无法在 Whosebug 中运行
我想提前 2 周启动我的日期时间选择器....这是我的代码
<div class="container">
<div class="row">
<div class='col-sm-3'>
<input type='text' class="form-control" id='datetimepicker4' />
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker4').datetimepicker();
});
</script>
试试这个代码....
<div class="container">
<div class="row">
<div class='col-sm-3'>
<input type='text' class="form-control" id='datetimepicker4' />
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker4').datetimepicker({
defaultDate: '+7d'
});
});
</script>
假设您正在使用这个库:https://eonasdan.github.io/bootstrap-datetimepicker/
$(function () {
$('#datetimepicker9').datetimepicker({
viewMode: 'years',
defaultDate: formatDate(getDateTwoWeeksFromNow())
});
});
function getDateTwoWeeksFromNow() {
new Date(+new Date + 12096e5);
}
function formatDate(date) {
return [date.getDate(), date.getMonth(),date.getFullYear()].join('/')
}
给你一个解决方案https://jsfiddle.net/0Ltv25o8/5532/
$('#datetimepicker2').datetimepicker({
defaultDate: moment().add('days', 14)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/src/js/bootstrap-datetimepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<div class="row">
<div class="col-md-12">
<input type="text" class="form-control" id="datetimepicker2" />
</div>
</div>
我用moment加了14天
您也可以添加周而不是天
$('#datetimepicker2').datetimepicker({
defaultDate: moment().add('weeks', 2)
});
用于禁用过去的日期
$('#datetimepicker2').datetimepicker({
minDate: moment().add('days', 14)
});
希望对您有所帮助。
请参考 jsFiddle,因为库 link.
导致代码无法在 Whosebug 中运行