this is my code
var myDate = new Date();
todaysDate = ((myDate.getDate()) + '/' + (myDate.getMonth()) + '/' + (myDate.getFullYear()));
$('#txtEndDate').val(todaysDate);
I need txtEndDate's value = today's date - one week
this is my code
var myDate = new Date();
todaysDate = ((myDate.getDate()) + '/' + (myDate.getMonth()) + '/' + (myDate.getFullYear()));
$('#txtEndDate').val(todaysDate);
I need txtEndDate's value = today's date - one week
You can modify a date using setDate
. It automatically corrects for shifting to new months/years etc.
var oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
然后继续以任何你喜欢的方式将日期呈现为字符串.