Search code examples
javascripttypescriptmomentjsmoment-timezone

how to use moment js utc time to get a countries different timezone


I have the following populated list of timezones that a user can select example

{name: '(UTC-12:00) International Date Line West', offset: '-12:00:00'}
{name: '(UTC-11:00) Coordinated Universal Time-11', offset: '-11:00:00'}
{name: '(UTC-10:00) Aleutian Islands', offset: '-10:00:00'}
{name: '(UTC-06:00) Guadalajara, Mexico City, Monterrey', offset: '-06:00:00'}
{name: '(UTC-06:00) Saskatchewan', offset: '-06:00:00'}

when the user selects a timezone how do i get the actual time and date of the zone they selected?

i can get the following local time as follows

var today = Moment();
        this.date = today.format("dddd,D MMM YYYY");
this.times = Moment().format("HH:mm:ss");

But im not sure how to get the timezones of the different locations. so for example if they selected (UTC-12:00) International Date Line West how do i show the date and time of that location?


Solution

  • Example From Docs:

    let moment = require('moment-timezone');
    moment().tz("America/Los_Angeles").format();