0

I understand that this question is being asked several times. But I couldn't find my code to get working anyway.

I have the following strings and I want to convert my local time to the desired time zone.

For example:

var localtime; // 11:30
var localtimezone; // (UTC-08:00) Pacific Time (US & Canada)
var desiredtimezone; // (UTC-06:00) Central Time (US & Canada)

This is a code I am using from this article: Convert date to another timezone in JavaScript

Code

var localtime; // 11:30
var localtimezone; // (UTC-08:00) Pacific Time (US & Canada)
var desiredtimezone; // (UTC-06:00) Central Time (US & Canada)

alert(toTimeZone(localtime, desiredtimezone));

function toTimeZone(time, zone) {
    var format = 'YYYY/MM/DD HH:mm:ss ZZ';
    return moment(time, format).tz(zone).format(format);
}

Based on the above example: my local time is 11:30 and I want to convert it to the time (which should be: 1:30) based on the desiredtimezone.

I will really appreciate your help.

orbnexus
  • 737
  • 1
  • 9
  • 38

0 Answers0