@easepick/datetime

中文文档
1.2.1发布于 2023/02/23GPL-2.0-or-laterTypeScriptESM + CJS零依赖近 30 天下载 7.1万

DateTime object for easepick.

原始使用文档
文档目录4 节
  1. Documentation
  2. DateTime() constructor
  3. Methods
  4. Tokens format

@easepick/datetime

npm version

This package does not need to be installed if you are using @easepick/bundle.

DateTime library for easepick.

Documentation

https://easepick.com/packages/datetime

DateTime() constructor

Creates a JavaScript DateTime instance that represents a single moment in time.
Using: new DateTime(date, format, lang)

argumenttypedefault valuedescription
dateDate
string
number
nullDate object or date string or number (unix timestamp).
formatstring'YYYY-MM-DD'Required when you provide date argument as string. Must match a string value for proper parsing.
langstring'en-US'Affects month names (MMM, MMMM tokens).

You can omit all arguments and call new DateTime(). This will create a DateTime object represents the current date.

Methods

nameargumentsdescription
getWeek-Returns a week number of date
clone-Returns a copy of date
toJSDate-Returns Date object.
inArray(array, inclusivity)Find DateTime object in passed DateTime array.
isBetween(date1, date2, inclusivity)Check if a DateTime is between two other DateTime.
isBefore(date, unit)Check if a DateTime is before another DateTime. unit are day, month, year.
isSameOrBefore(date, unit)Check if a DateTime is before or the same as another DateTime. unit are day, month.
isAfter(date, unit)Check if a DateTime is after another DateTime.. unit are day, month, year.
isSameOrAfter(date, unit)Check if a DateTime is after or the same as another DateTime. unit are day, month.
isSame(date, unit)Check if a DateTime is the same as another DateTime. unit are day, month.
add(duration, unit)Mutates the original DateTime by adding unit. unit are day, month.
subtract(duration, unit)Mutates the original DateTime by subtracting unit. unit are day, month.
diff(date, unit)Returns diff between two DateTime. unit are day, month.
format(format, lang)Format output. See tokens format for format argument. lang affects month names (MMM, MMMM tokens).

Tokens format

Tokens are case-sensitive.

TokenOutput
Day of MonthD1 2 … 30 31
DD01 02 … 30 31
MonthM1 2 … 11 12
MM01 02 … 11 12
MMMJan Feb … Nov Dec
MMMMJanuary February … November December
YearYY70 71 … 29 30
YYYY1970 1971 … 2029 2030
Hours (24 hour time)H0 1 … 22 23
HH01 02 … 22 23
Minutesm1 2 … 58 59
mm01 02 … 58 59
Secondss1 2 … 58 59
ss01 02 … 58 59

版本与发布记录

@easepick/datetime 共发布 22 个版本,首次发布于 2022/01/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.1latest2023/02/233 年前
1.2.02022/05/214 年前
1.1.72022/04/194 年前
1.1.62022/04/194 年前
1.1.52022/04/114 年前
1.1.42022/04/114 年前

其他发布通道:beta → 1.0.2-beta.0。

关于 @easepick/datetime 的常见问题

@easepick/datetime 是什么?

DateTime object for easepick.

如何安装 @easepick/datetime?

在项目目录运行 npm install @easepick/datetime,或使用 pnpm add / yarn add / bun add。

@easepick/datetime 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@easepick/datetime 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@easepick/datetime 可以商用吗?

@easepick/datetime 使用 GPL-2.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以兼容的 GPL 许可开源。仅在内部使用、不对外分发时不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@easepick/datetime 的下载量有多少?

根据 npm 官方下载统计,@easepick/datetime 在 2026/10/13 – 2026/11/11 这 30 天内被下载 70,788 次,日均约 2,360 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@easepick/datetime 还在维护吗?

最新版本 1.2.1 发布于 2023/02/23(3 年前);至今共发布 22 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/01/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。