1 回答

TA貢獻1884條經(jīng)驗 獲得超4個贊
您應(yīng)該意識到,調(diào)整 Date 對象.setDate()將更改原始日期。所以你需要兩個獨立的日期對象:
const frmDate = new Date();
const toDate = new Date();
但還toDate需要5天的時間。最直接的方法就是現(xiàn)在使用.setDate()上的方法toDate。通過獲取日期frmDate并添加您的 5 天來做到這一點:
toDate.setDate(frmDate.getDate() + 5);
結(jié)果如下:
const frmDate = new Date();
const toDate = new Date()
toDate.setDate(frmDate.getDate() + 5);
const ccCustInfo = {
cropConsultant: 'Test this',
customerName: 'Customer',
customerBranch: 'MULBERRY ',
shippingAddress:'address',
contractType: 'SKU',
contVfrom: 'Contract Valid From',
contVto: 'Contract Valid To',
internalNotes: 'Internal Notes',
contVfrmDate: frmDate.toLocaleString('en-US',{month: 'numeric', day: 'numeric', year: 'numeric'}),
contVtoDate: toDate.toLocaleString('en-US',{month: 'numeric', day: 'numeric', year: 'numeric'})
}
console.log(ccCustInfo);
添加回答
舉報