Commit f2a2c3ad authored by qinhaitao's avatar qinhaitao

feat: 🎸 获取年份等api

parent 5a987d7c
......@@ -20,6 +20,13 @@ const EIGHT_HOURS = 8 * 60 * 60 * 1000
* getTimestamp 时间戳
* getStartTimestamp 某天开始的时间戳
* getEndTimestamp 某天结束的时间戳
* getYear 获取年份
* getMonth 获取月份
* getDay 获取天
* getHour 获取小时
* getMinute 获取分钟
* geSecond 获取秒数
* getMillisecond 获取毫秒
* }
*/
export function formatDate(date: string | number = Date.now()) {
......@@ -28,6 +35,13 @@ export function formatDate(date: string | number = Date.now()) {
format: (template = 'YYYY-MM-DD') => dayjs(beijingDate).format(template),
getTimestamp: () => (typeof date === 'number' ? date : dayjs(date).valueOf() - EIGHT_HOURS),
getStartTimestamp: () => getStartTimestamp(dayjs(beijingDate).format('YYYY/MM/DD')),
getEndTimestamp: () => getEndTimestamp(dayjs(beijingDate).format('YYYY/MM/DD'))
getEndTimestamp: () => getEndTimestamp(dayjs(beijingDate).format('YYYY/MM/DD')),
getYear: () => dayjs(beijingDate).get('year'),
getMonth: () => dayjs(beijingDate).get('month'),
getDay: () => dayjs(beijingDate).get('day'),
getHour: () => dayjs(beijingDate).get('hour'),
getMinute: () => dayjs(beijingDate).get('minute'),
geSecond: () => dayjs(beijingDate).get('second'),
getMillisecond: () => dayjs(beijingDate).get('millisecond')
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment