npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

dayjs-date-tools

v1.0.11-alpha

Published

基于dayjs的时间工具函数

Downloads

17

Readme

dayjs-date-tools

基于 dayjs 的常用时间工具函数,使用 typescript 编写,cypress 测试

CHANGELOG

CHANGELOG.md

安装

npm i -S dayjs-date-tools

下文函数均支持按需引用

range

getFirstDayAndEndDayOfMonth

获取日期所在月份的第一天和最后一天

getFirstDayAndEndDayOfMonth("2022-03", "YYYY-MM-DD"); //["2022-03-01","2022-03-31"]

getFirstDayAndEndDayOfWeek

获取日期所在周的第一天和最后一天

getFirstDayAndEndDayOfWeek("2022-03-11", "YYYY-MM-DD"); //["2022-03-07","2022-03-13"]

isBetween

判断日期是否在 start end 范围内

isBetween("2022-01-01", "2022-01-01", "2022-03-12"); //true
isBetween("2021-12-31", "2022-01-01", "2022-03-12"); //false

diff

计算日期的差值

diff("2022-03-14 00:00:00", "2022-03-13 23:59:59"); //1000 不传unit默认为毫秒
diff("2022-03-14 00:00:00", "2022-03-13 23:59:59", "second"); //1 秒
diff("2022-03-14 00:00:00", "2022-03-13 23:59:00", "minute"); //1 分钟
diff("2022-03-14 1:00:00", "2022-03-13 22:00:00", "hour"); //1 小时
diff("2022-03-14", "2022-03-13", "day"); //1 天
diff("2022-03-13", "2022-03-06", "week"); //1 周
diff("2022-04", "2022-03", "month"); //1 月
diff("2023-03", "2022-03", "year"); //1 年

compare

isSameOrBefore

判断日期是否小于等于另一个日期

isSameOrBefore("2022-03-12", "2022-03-12"); //true
isSameOrBefore("2022-03-11", "2022-03-12"); //true
isSameOrBefore("2022-03-13", "2022-03-12"); //false

isSameOrAfter

判断日期是否大于等于另一个日期

isSameOrBefore("2022-03-12", "2022-03-12"); //true
isSameOrBefore("2022-03-11", "2022-03-12"); //true
isSameOrBefore("2022-03-13", "2022-03-12"); //false

format

format

格式化日期

format("2022/03/14"); //2022-03-14 默认格式
format("2022-03-14", "YYYY/MM/DD"); //2022/03/14
format("2022-03-14", "YYYY-MM"); //2022-03

getMonth

获取月份

getMonth("2022-03"); //3

getChineseMonth

获取中文月份

getChineseMonth("2022-03"); //3月

getWeek

获取当前周是全年第几周

getWeek("2022-01-02"); //52
getWeek("2022-12-31"); //52
getWeek("2022-01-03"); //1
getWeek("2022-01-10"); //2

getStartOfWeek

获取当前周一

getStartOfWeek("2022-03-14"); //2022-03-14
getStartOfWeek("2022-03-13"); //2022-03-07

getEndOfWeek

获取当前周末

getEndOfWeek("2022-03-14"); //2022-03-20
getEndOfWeek("2022-03-13"); //2022-03-13

getStartOfMonth

获取当月第一天

getStartOfMonth("2022-03-14"); //2022-03-01
getStartOfMonth("2022-02"); //2022-02-01

getEndOfMonth

获取当月最后一天

getEndOfMonth("2022-03-14"); //2022-03-31
getEndOfMonth("2022-02"); //2022-02-28