@financial-times/ft-date-format

中文文档
4.0.0发布于 2025/05/21MITCommonJS零依赖近 30 天下载 6413

Utility for formatting and updating dates for Financial-Times customer-facing products

原始使用文档
文档目录5 节
  1. Usage
  2. JavaScript
  3. Migration Guide
  4. Contact
  5. Licence

ft-date-format

ft-date-format provides javascript utilities for formatting and updating dates in FT style.

Usage

JavaScript

ft-date-format#format(date, tpl)

Returns a date formatted as a string

  • date: A javascript Date object or a valid string to pass to the Date constructor
  • tpl: A string specifying what format to output the date in:
    • 'datetime': formats the date in the standard FT long format, including the time. E.g. May 15, 2014 8:10 am
    • 'date': formats the date in the standard FT long format. E.g. May 15, 2014
    • Any other string using widespread conventions for time/date placeholders, which will be replaced with values extracted from the date provided. See ./main.js for an up to date list of supported formats. To avoid e.g. the mm in common being replaced with the month prefix with a double backslash co\\mmon i.e. In most cases custom date formats should not be used, in favour of the standard FT date and datetime formats

ft-date-format#timeAgo(date)

Returns the relative time since the given date, formatted as a human readable string e.g. 13 minutes ago.

ft-date-format#ftTime(date)

Returns relative time or timestamp for a given date, in accordance with FT date formatting conventions.

  • date: A javascript Date object or a valid string to pass to the Date constructor

ft-date-format#asTodayOrYesterdayOrNothing(date)

Returns 'yesterday', 'today' or '' for a given date. You can request this formatting for ft-date-format components by adding data-ft-date-format-format="today-or-yesterday-or-nothing".

  • date: A javascript Date object or a valid string to pass to the Date constructor

Migration Guide

StateMajor VersionLast Minor ReleaseMigration guide
✨ active2N/Amigrate to v2
⚠ maintained11.0.5-

Contact

If you have any questions, comments, or need help using ft-date-format, please either raise an issue, visit #ft-origami or email Origami Support.


Licence

This software is published by the Financial Times under the MIT licence.

版本与发布记录

@financial-times/ft-date-format 共发布 11 个版本,首次发布于 2019/03/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.0latest2025/05/211.5 年前
3.0.02023/03/143 年前
2.1.02021/11/294 年前
2.0.0-beta.02021/08/125 年前
2.0.02021/06/185 年前
1.0.52021/01/125 年前

关于 @financial-times/ft-date-format 的常见问题

@financial-times/ft-date-format 是什么?

Utility for formatting and updating dates for Financial-Times customer-facing products

如何安装 @financial-times/ft-date-format?

在项目目录运行 npm install @financial-times/ft-date-format,或使用 pnpm add / yarn add / bun add。

@financial-times/ft-date-format 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/financial-times__ft-date-format 是否存在。

@financial-times/ft-date-format 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@financial-times/ft-date-format 可以商用吗?

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

@financial-times/ft-date-format 的下载量有多少?

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

@financial-times/ft-date-format 还在维护吗?

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