javascript 使用 momentjs 进行时区转换

javascript timezone conversion using momentjs

我有一个 UTC 日期和时间以及一个时区我想将此日期和时间转换为给定的时区等效值,例如如果 UTC 日期为 2022-01-10T00:00:00.000Z,这意味着 1 月 10 日 00:00 am,当我将其转换为纽约时区时,等效输出应为 2022-01-09T19:00:00.000Z 即 1 月 9 日 07:00 下午或 19:00,因为它距 UTC 的时间为 -05:00。 我怎样才能做到这一点,任何人都可以提供帮助吗? 时区可以是任何时区。 感谢您的帮助。

like 
let date= '2022-01-10T00:00:00.000Z';
let timezone = 'America/New_York';

您可以这样使用 moment-timezone

const moment = require('moment-timezone')

const date = '2022-01-10T00:00:00.000Z';
const timezone = 'America/New_York';

const convertedDate = moment.utc(date)  // create Moment object from date in UTC
  .tz(timezone)                        // convert to provided time zone
  .format('YYYY-MM-DD hh:mm:ss A')    // display in format

console.log(convertedDate)
// 2022-01-09 07:00:00 PM