@wordpress/date


目录

Date module for WordPress.

Installation

Install the module

npm install @wordpress/date --save

This package assumes that your code will run in an ES2015+ environment. If you’re using an environment that has limited or no support for such language features and APIs, you should include the polyfill shipped in @wordpress/babel-preset-default in your code.

API

date

Formats a date (like date() in PHP).

Parameters

Returns

dateI18n

Formats a date (like wp_date() in PHP), translating it into site’s locale.

Backward Compatibility Notice: if timezone is set to true, the function behaves like gmdateI18n.

Parameters

Returns

format

Formats a date. Does not alter the date’s timezone.

Parameters

Returns

getDate

Create and return a JavaScript Date Object from a date string in the WP timezone.

Parameters

Returns

getSettings

Returns the currently defined date settings.

Returns

gmdate

Formats a date (like date() in PHP), in the UTC timezone.

Parameters

Returns

gmdateI18n

Formats a date (like wp_date() in PHP), translating it into site’s locale and using the UTC timezone.

Parameters

Returns

humanTimeDiff

Returns a human-readable time difference between two dates, like human_time_diff() in PHP.

Parameters

Returns

isInTheFuture

Check whether a date is considered in the future according to the WordPress settings.

Parameters

Returns

setSettings

Adds a locale to moment, using the format supplied by wp_localize_script().

Parameters

Contributing to this package

This is an individual package that’s part of the Gutenberg project. The project is organized as a monorepo. It’s made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to npm and used by WordPress as well as other software projects.

To find out more about contributing to this package or Gutenberg as a whole, please read the project’s main contributor guide.


版本号 #2
由 壳壳虫 创建于 2026-10-31 18:18:24 UTC
由 壳壳虫 更新于 2026-10-31 18:18:25 UTC