我正在使用angular 12,在这里计算天的基础上,2个日期工程罚款与铬,但同样的事情失败,在火狐。
TS:使用Moment,在firefox下出现无效日期错误:
getDaysCount(firstDate: any, secondDate: any) {
let first = moment(firstDate, 'MM-DD-YYYY');
let second = moment(secondDate, 'MM-DD-YYYY');
return second.diff(first, 'days');
}
“2022年11月12日”);
var Difference_In_Days = Math.ceil(Math.abs(secondDate - firstDate) / (1000 * 60 * 60 * 24));
这在火狐中给出了NAN,但在Chrome中给出了2。
1条答案
按热度按时间ldioqlga1#
Take a look at this answer . Firefox requires the date in
yyyy-mm-dd
format. If you make the change, it works in both Firefox and Chrome.FYI, you cannot use
Math.ceil
on strings, you need to convert them to milliseconds first.To include negative numbers in the result, remove
Math.abs
from the function.Firefox console:
Chrome console: