TZ


TZ 环境变量用于指定时区配置。

虽然 Node.js 对 TZ 的支持不会处理所有 TZ 在其他环境中处理的方式,但它将支持基本的时区 ID(例如 'Etc/UTC''Europe/Paris''America/New_York')。 它可能支持其他一些缩写或别名,但强烈建议不要使用这些缩写或别名,并且不能保证。

$ TZ=Europe/Dublin node -pe "new Date().toString()"
Wed May 12 2021 20:30:48 GMT+0100 (Irish Standard Time)

The TZ environment variable is used to specify the timezone configuration.

While the Node.js support for TZ will not handle all of the various ways that TZ is handled in other environments, it will support basic timezone IDs (such as 'Etc/UTC', 'Europe/Paris' or 'America/New_York'. It may support a few other abbreviations or aliases, but these are strongly discouraged and not guaranteed.

$ TZ=Europe/Dublin node -pe "new Date().toString()"
Wed May 12 2021 20:30:48 GMT+0100 (Irish Standard Time)