diff --git a/src/module/timeLabel.js b/src/module/timeLabel.js index e2860cb..25b39e8 100644 --- a/src/module/timeLabel.js +++ b/src/module/timeLabel.js @@ -263,7 +263,9 @@ export function dateLabel(date, maxDate, minDate) { * @returns {string} - The suitable time format string. */ export const setTimeStringFormatBaseOnTimeDifference = (minTimeStamp, maxTimeStamp) => { - const timeDifferenceInSeconds = (minTimeStamp - maxTimeStamp) / 1000; + const laterDate = new Date(maxTimeStamp); + const earlyDate = new Date(minTimeStamp); + const timeDifferenceInSeconds = (laterDate - earlyDate) / 1000; let dateFormat; if (timeDifferenceInSeconds < 60) { @@ -273,7 +275,7 @@ export const setTimeStringFormatBaseOnTimeDifference = (minTimeStamp, maxTimeSta } else if (timeDifferenceInSeconds < 86400) { // 86400 秒 = 24 小時 dateFormat = 'MM/DD HH:mm'; // 小時 } else if (timeDifferenceInSeconds < 2592000) { // 2592000 秒 = 30 天 - dateFormat = 'MM/DD'; // 天 + dateFormat = 'YYYY/MM/DD'; // 天 } else { dateFormat = 'YYYY/MM'; // 月 }