4

I am trying to convert Local Date/Time to other Time Zone with JavaScript.

Dates are stored in DB as UTC.

For example,

value = "2014-08-15T11:09:10Z"

var dt = new Date(value)

the output will be in my Local Timezone

Fri Aug 15 2014 18:09:10 GMT+0700 (ICT)

But how can I convert this to other Time Zone (i.e - Moscow) by using JavaScript.

Athafoud
  • 2,708
  • 2
  • 43
  • 53
Metal
  • 395
  • 2
  • 12

2 Answers2

2

You can use JS library such as timezone-js. You could write code like this :

 var format = 'YYYY/MM/DD HH:mm:ss ZZ';
 var dt = new timezoneJS.Date(format , 'Europe/London');
 dt.setTimezone("Asia/Jakarta");

you can also check out other JS library like:

Vivek Pratap Singh
  • 8,296
  • 5
  • 17
  • 34
2

You may try like this:

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

Also check moment.js

Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319