Установите часы в другом часовом поясе с помощью Moment.js и JavaScript

Чтобы установить часы в другом часовом поясе с помощью Moment.js, вы можете воспользоваться следующими методами:

Метод 1: использование Moment.js с часовым поясом

// Install moment-timezone package
npm install moment-timezone
// Import required modules
const moment = require('moment-timezone');
// Set the clock in another timezone
const desiredTimezone = 'America/New_York';
const currentTime = moment().tz(desiredTimezone).format('YYYY-MM-DD HH:mm:ss');
console.log(`Current time in ${desiredTimezone}: ${currentTime}`);

Метод 2: использование Moment.js без часового пояса

// Import the moment module
const moment = require('moment');
// Set the clock in another timezone
const desiredTimezone = 'America/New_York';
const currentTime = moment().utcOffset(desiredTimezone).format('YYYY-MM-DD HH:mm:ss');
console.log(`Current time in ${desiredTimezone}: ${currentTime}`);

Метод 3. Использование встроенного в JavaScript объекта Date (без Moment.js)

// Set the clock in another timezone
const desiredTimezone = 'America/New_York';
const currentTime = new Date().toLocaleString('en-US', { timeZone: desiredTimezone });
console.log(`Current time in ${desiredTimezone}: ${currentTime}`);

Обратите внимание, что Moment.js устарел, и для обработки часовых поясов рекомендуется использовать встроенный объект JavaScript Date или другие современные библиотеки даты и времени.