如何将 daterangepicker 设置为今天 + 1 天?
How can I set the daterangepicker to today + 1 day?
我想将我的 daterangepicker 的开始日期设置为 today + 1 day
,将我的 daterangepicker 的结束日期设置为 today + 2 days
。
<script type="text/javascript">
$(document).ready(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('input[name="daterange"]').daterangepicker({
minDate: new Date(currentYear, currentMonth, currentDate)
, dateFormat: 'yy-mm-dd'
, startDate: +1
, endDate: +2
, locale: {
format: 'DD.MM.YYYY'
}
});
});
</script>
我的结果是09.08.2017 - 09.08.2017
但我希望10.08.2017 - 11.08.2017
您的问题在于以下几行:
, startDate: +1
, endDate: +2
更改为:
, startDate: moment(date).add(1,'days')
, endDate: moment(date).add(2,'days')
片段:
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('input[name="daterange"]').daterangepicker({
minDate: new Date(currentYear, currentMonth, currentDate)
, dateFormat: 'yy-mm-dd'
, startDate: moment(date).add(1,'days')
, endDate: moment(date).add(2,'days')
, locale: {
format: 'DD.MM.YYYY'
}
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />
<input type="text" name="daterange" value="01/01/2015 - 01/31/2015" />
我想将我的 daterangepicker 的开始日期设置为 today + 1 day
,将我的 daterangepicker 的结束日期设置为 today + 2 days
。
<script type="text/javascript">
$(document).ready(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('input[name="daterange"]').daterangepicker({
minDate: new Date(currentYear, currentMonth, currentDate)
, dateFormat: 'yy-mm-dd'
, startDate: +1
, endDate: +2
, locale: {
format: 'DD.MM.YYYY'
}
});
});
</script>
我的结果是09.08.2017 - 09.08.2017
但我希望10.08.2017 - 11.08.2017
您的问题在于以下几行:
, startDate: +1
, endDate: +2
更改为:
, startDate: moment(date).add(1,'days')
, endDate: moment(date).add(2,'days')
片段:
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('input[name="daterange"]').daterangepicker({
minDate: new Date(currentYear, currentMonth, currentDate)
, dateFormat: 'yy-mm-dd'
, startDate: moment(date).add(1,'days')
, endDate: moment(date).add(2,'days')
, locale: {
format: 'DD.MM.YYYY'
}
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />
<input type="text" name="daterange" value="01/01/2015 - 01/31/2015" />