@duskmoon-dev/el-datetime

中文文档
1.10.3发布于 2026/11/11MITTypeScriptESM + CJS构建来源已验证近 30 天下载 2589

Display-only DuskMoon custom element for formatting ISO dates and datetimes

原始使用文档
文档目录7 节
  1. Installation
  2. Registration
  3. Usage
  4. Attributes
  5. Format tokens
  6. Input and time-zone behavior
  7. CSS parts

@duskmoon-dev/el-datetime

A display-only Web Component that formats ISO dates and datetimes as semantic <time> content.

Installation

bun add @duskmoon-dev/el-datetime

Registration

import '@duskmoon-dev/el-datetime/register';

Or register it explicitly:

import { register } from '@duskmoon-dev/el-datetime';

register();

Usage

<el-dm-datetime
  value="2026-08-11T14:30:45Z"
  format="YYYY-MM-DD HH:mm:ss"
  time-zone="Asia/Shanghai"
></el-dm-datetime>

The example renders 2026-08-11 22:30:45 while retaining the original value in the inner <time datetime="..."> attribute.

Attributes

AttributeTypeDefaultDescription
valuestring''ISO date or datetime to display
formatstring'YYYY-MM-DD HH:mm'Output format
time-zonestring''IANA time zone for timestamps with Z or an offset; empty uses the browser time zone

Format tokens

TokenOutput
YYYY, YYFour- or two-digit year
M, MMMonth without or with zero-padding
D, DDDay without or with zero-padding
H, HH24-hour time without or with zero-padding
h, hh12-hour time without or with zero-padding
m, mmMinutes without or with zero-padding
s, ssSeconds without or with zero-padding
SSSMilliseconds
A, aUpper- or lowercase meridiem

Wrap literal text in brackets so token letters are not interpreted:

<el-dm-datetime value="2026-08-11T14:30:45" format="YYYY-MM-DD [at] h:mm A"></el-dm-datetime>

This renders 2026-08-11 at 2:30 PM.

Input and time-zone behavior

  • Accepted values are YYYY-MM-DD and ISO datetimes such as 2026-08-11T14:30, 2026-08-11T14:30:45.123456Z, or 2026-08-11T14:30:45+08:00. Fractional seconds are truncated to milliseconds for the SSS token.
  • Date-only and offsetless datetime values are wall-clock values and are not shifted by time-zone.
  • Values with Z or an explicit offset represent an instant. They are converted to time-zone, or to the browser's local time zone when the attribute is omitted.
  • Invalid values, impossible dates, and invalid time zones render empty content without throwing.

Use an explicit Z or offset whenever time-zone conversion matters.

CSS parts

PartDescription
timeThe semantic <time> element

版本与发布记录

@duskmoon-dev/el-datetime 共发布 19 个版本,首次发布于 2026/08/11;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.10.3latest2026/11/112 天前
1.10.22026/10/2222 天前
1.10.12026/10/1627 天前
1.10.02026/10/1628 天前
1.9.32026/10/131 个月前
1.9.22026/10/131 个月前

关于 @duskmoon-dev/el-datetime 的常见问题

@duskmoon-dev/el-datetime 是什么?

Display-only DuskMoon custom element for formatting ISO dates and datetimes

如何安装 @duskmoon-dev/el-datetime?

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

@duskmoon-dev/el-datetime 支持 TypeScript 吗?

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

@duskmoon-dev/el-datetime 支持 ESM 还是 CommonJS?

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

@duskmoon-dev/el-datetime 可以商用吗?

@duskmoon-dev/el-datetime 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@duskmoon-dev/el-datetime 的下载量有多少?

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

@duskmoon-dev/el-datetime 还在维护吗?

最新版本 1.10.3 发布于 2026/11/11(2 天前);至今共发布 19 个版本,其中过去 12 个月发布了 19 个;首次发布于 2026/08/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。