如何使用JavaScript添加减去日期?

如何使用JavaScript添加减去日期?,第1张

如何使用JavaScript添加/减去日期?

码:

var date = new Date('2011', '01', '02');alert('the original date is ' + date);var newdate = new Date(date);newdate.setDate(newdate.getDate() - 7); // minus the datevar nd = new Date(newdate);alert('the new date is ' + nd);

使用Datepicker:

$("#in").datepicker({    minDate: 0,    onSelect: function(dateText, inst) {       var actualDate = new Date(dateText);       var newDate = new Date(actualDate.getFullYear(), actualDate.getMonth(), actualDate.getDate()+1);        $('#out').datepicker('option', 'minDate', newDate );    }});$("#out").datepicker();​

可能会派上用场的其他东西:

getDate()   Returns the day of the month (from 1-31)getDay()    Returns the day of the week (from 0-6)getFullYear()   Returns the year (four digits)getHours()  Returns the hour (from 0-23)getMilliseconds()   Returns the milliseconds (from 0-999)getMinutes()    Returns the minutes (from 0-59)getMonth()  Returns the month (from 0-11)getSeconds()    Returns the seconds (from 0-59)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5101256.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存