引导3日期拾取器和时刻问题
Bootstrap 3 datepicker and moment issue
我在一个页面上有2个bootstrap 3个日期摘取器。一个是发行日期,另一个是到期日期。我想将due_date
设置为issue_date + transactionDaysTerms
(例如14
天)。
$('#issue_date').datepicker({
}).on('changeDate', function(event){
$(this).datepicker('hide');
var calculatedEndDate = moment($('#issue_date').val()).add(transactionDaysTerms, 'days');
$('#issue_date').datepicker('setEndDate', calculatedEndDate);
$('#due_date').datepicker('setEndDate', calculatedEndDate);
}).on('clearDate', function(event){
$(this).datepicker('setDate', today);
});
我已经尝试了moment
的各种格式,但无济于事。此代码在
Uncaught TypeError: date.match is not a function
我怎样才能从moment.js得到日期格式与日期选择器一起工作?
效果很好。
$('#issue_date').datepicker({
}).on('changeDate', function(event){
$(this).datepicker('hide');
var calculatedEndDate = moment($(this).datepicker('getDate')).add(transactionDays, 'days').toDate();
$('#issue_date').datepicker('setEndDate', calculatedEndDate);
$('#due_date').datepicker('setDate', calculatedEndDate);
}).on('clearDate', function(event){
var calculatedEndDate = moment(today).add(transactionDays, 'days').format('L');
$('#issue_date').datepicker('setEndDate', calculatedEndDate);
$('#due_date').datepicker('setDate', calculatedEndDate);
});
我只需要在moment call结束时使用.toDate()
。
难道不能使用getDate
从日期选择器中获取时间戳,然后将天数相乘得到毫秒,将其相加,并设置结束日期
$('#issue_date').datepicker().on('changeDate', function(event) {
$(this).datepicker('hide');
var date = $(this).datepicker('getDate');
var days = transactionDaysTerms * 24 * 60 * 60 * 1000;
var calculatedEndDate = new Date( date.getTime() + days );
$('#issue_date, #due_date').datepicker('setEndDate', calculatedEndDate);
}).on('clearDate', function(event) {
$(this).datepicker('setDate', today);
});
小提琴
相关文章:
- 在指令控制器中使用$attrs时出现问题
- 将PHP变量传递给jQuery时遇到问题
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- 参数变量出现ngTable指令问题
- 剑道网格jQuery动画()问题
- 我的jQuery插件参数没有正确启动,遇到了问题
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- TableExport jquery插件:文件名和扩展名问题
- JavaScript Pub/Sub属性访问问题
- JavaScript异步问题
- 如何解决Yii中的页面刷新问题
- Safari(Mac OS)上的jQuery平滑滚动问题
- jqGrid树网格问题
- 使用正则表达式评估电子邮件地址时出现性能问题
- 如何消除代码中的未定义和其他问题
- 使用时刻验证日期时出现问题.js按格式
- 时刻JS:问题减去分钟
- 操作日期时的时刻日期问题
- Moment.js和meteor,使用存储时刻的问题
- 引导3日期拾取器和时刻问题