React 獲取上個月第一天起始時間 00:00:00

   獲取上個月第一天起始時間 00:00:00 封裝起來作法

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

const start = new Date(thisYear, thisMonth - 1, '01').getTime() / 1000;
return start;
}

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

在想要引用的檔案引用

import { getLastMonthStartTime } from '封裝js路徑';
console.log('上個月第一天起始時間', getLastMonthStartTime())

留言

熱門文章