1
我已經使用以下腳本在一個字段中輸入日期,爲其添加日期以填充另一個字段。現在我想做相反的事情,輸入日期並減去天數來填充不同的字段。使用parseInt減去日期
//Script below is the addition
//Field: CTS D/R
var dString = getField("Task Anlys").value;
var dParts = dString.split("-");
var mydate=new Date();
mydate.setDate(dParts[0]);
mydate.setMonth(monthsByName[dParts[1]]);
mydate.setYear(dParts[2]);
//Date + 14 Days * 24 Hours * 60 Minutes * 60 Seconds * 1000 milliseconds
var calNewDays = 14 * 24 * 60 * 60 * 1000;
//Set new date
mydate.setTime(calNewDays + parseInt(mydate.getTime()));
var year=mydate.getYear() + 1900;
var month=mydate.getMonth();
var day=mydate.getDate();
getField("CTS D/R").value = day + "-" + months[month] + "-" + year;`
//Script below is an attempt for subtraction
//Date = 30 Days * 24 Hours * 60 Minutes * 60 Seconds * 1000 milliseconds
var calNewDays = 30 * 24 * 60 * 60 * 1000;
//Set new date
mydate.setTime(parseInt(mydate.getTime() - calNewDays));`
什麼問題? –
我建議查找date.js腳本。它有各種方便的日期功能。 –
處理日期時,最好使用像[Moment.js](http://momentjs.com/)這樣的庫, –