- 使用Date
let date_str1 = '2023-01-01';
let date_str2 = '2023-12-12';
let day1 = new Date(date_str1).getTime();
let day2 = new Date(date_str2).getTime();
let day_count = Math.floor((day1 - day2) / 86400000);
- 使用moment
import moment from 'moment';
let date_str1 = '2023-01-01';
let date_str2 = '2023-12-12';
let date1 = moment(date_str1, 'YYYY-MM-DD');
let date2 = moment(date_str2, 'YYYY-MM-DD')
let day_count = date2.diff(date1, 'days')