@wordpress/date 是 WordPress 的日期处理模块,提供了一系列函数用于格式化、转换和比较日期,支持国际化、时区处理和与 PHP 日期函数的兼容性。该模块基于 ES2015+ 环境,需通过 npm 安装,并可集成 polyfill 以支持旧环境。
Date module for WordPress.
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.
Formats a date (like date() in PHP).
Related
Parameters
string: PHP-style formatting string. See php.net/date.Moment | Date | string | number: Date object or string, parsable by moment.js.string: Timezone to output result in or a UTC offset. Defaults to timezone from site.Returns
string: Formatted date in English.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.
Related
Parameters
string: PHP-style formatting string. See php.net/date.Moment | Date | string | number: Date object or string, parsable by moment.js.string | number | boolean: Timezone to output result in or a UTC offset. Defaults to timezone from site. Notice: boolean is effectively deprecated, but still supported for backward compatibility reasons.Returns
Formats a date. Does not alter the date’s timezone.
Parameters
string: PHP-style formatting string. See php.net/date.Moment | Date | string | number: Date object or string, parsable by moment.js.Returns
Create and return a JavaScript Date Object from a date string in the WP timezone.
Parameters
string | null: Date formatted in the WP timezone.Returns
Returns the currently defined date settings.
Returns
DateSettings: Settings, including locale data.Formats a date (like date() in PHP), in the UTC timezone.
Parameters
string: PHP-style formatting string. See php.net/date.Moment | Date | string | number: Date object or string, parsable by moment.js.Returns
Formats a date (like wp_date() in PHP), translating it into site’s locale and using the UTC timezone.
Parameters
string: PHP-style formatting string. See php.net/date.Moment | Date | string | number: Date object or string, parsable by moment.js.Returns
Returns a human-readable time difference between two dates, like human_time_diff() in PHP.
Parameters
Moment | Date | string | number: From date, in the WP timezone.Moment | Date | string | number: To date, formatted in the WP timezone.Returns
Check whether a date is considered in the future according to the WordPress settings.
Parameters
Date | string | number: Date String or Date object in the Defined WP Timezone.Returns
Adds a locale to moment, using the format supplied by wp_localize_script().
Parameters
DateSettings: Settings, including locale data.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.