React 獲取上個月最後一天結束時間 23:59:59

   獲取上個月最後一天結束時間 23:59:59 封裝起來作法

export function getLastMonthEndTime() {
const today = new Date();
const thisYear = today.getFullYear();
const thisMonth = today.getMonth();

const end = new Date(new Date(new Date(thisYear, thisMonth, 0).getTime() + 24 * 60 * 60 * 1000 - 1)).getTime() / 1000;
return end;
}

若不轉換時間軸 可以移除後面 .getTime() / 1000

在想要引用的檔案引用

import { getLastMonthEndTime } from '封裝js路徑';
console.log('上個月最後一天結束', getLastMonthEndTime())

留言

熱門文章