我有這個函數需要今天的日期並將它與兩週的時間進行比較。當它小於或等於當前日期時,它應該添加一個類。但是,如果是今天的日期,那麼它不起作用。否則,它工作正常。有任何想法嗎?由於與今天的日期相比,日期對象似乎並不準確
publicMethods.campaignEndDateAlert = function (dateString) {
if (!dateString) {
return dateString
};
var currentDate = new Date();
var twoWeeks = new Date();
twoWeeks.setDate(currentDate.getDate() + 14);
var inputDate = new Date(dateString);
// This is the part that doesn't seem to work - the first part of this if statement
if ((inputDate >= currentDate) && (inputDate <= twoWeeks)) {
dateString = '<span class="red">' + ax.Utils.RFCFormat(dateString, { excludeTime: true }) + '</span>';
} else {
dateString = ax.Utils.RFCFormat(dateString, { excludeTime: true })
};
return dateString;
};
InputDate是否生成有效的日期對象?你可以舉一個dateString的例子嗎? –
嗨,納達,它是。 – erics15
剛注意到「如果是今天的日期」部分 –