DEV Community

Cover image for toolkit-use npm package have added some functions
toolkituse
toolkituse

Posted on

toolkit-use npm package have added some functions

https://kennana.github.io/toolkit-use/guide/date/date.html

日期格式化示例

<script setup lang="ts">
import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"

const date = new Date()

const str = ToolkitUseDate.formatDate(date, 'yyyy-MM-dd HH:mm:ss')
</script>
Enter fullscreen mode Exit fullscreen mode

formatDate 参数说明

参数 说明 值类型
dateObj date实例 date
format 格式化 string

判断润年

import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"
ToolkitUseDate.isLeap(year: number)
Enter fullscreen mode Exit fullscreen mode

获取星期

import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"
ToolkitUseDate.getWeek(date: Date | string)
Enter fullscreen mode Exit fullscreen mode

获取月份天数

import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"
ToolkitUseDate.getMonthDays(year: number, month: number)
Enter fullscreen mode Exit fullscreen mode

数字补零

import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"
ToolkitUseDate.padLeftZero(str: number)
Enter fullscreen mode Exit fullscreen mode

获取今天日期

import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"
ToolkitUseDate.getToday(str = 'yyyy-mm-dd')
Enter fullscreen mode Exit fullscreen mode

获取上一天日期

import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"
ToolkitUseDate.getYesterday(str: string)
Enter fullscreen mode Exit fullscreen mode

获取下一天日期

import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"
ToolkitUseDate.getTomorrow(str: string)
Enter fullscreen mode Exit fullscreen mode

获取前n天日期

import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"
ToolkitUseDate.beforeNDay(date: string, n: number)
Enter fullscreen mode Exit fullscreen mode

获取后n天日期

import { ToolkitUseDate } from "toolkit-use/dist/date/index.esm"
ToolkitUseDate.afterNDay(date: string, n: number)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)