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,898
  • 3
  • 40
  • 58
Metal
  • 435
  • 3
  • 13

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
  • 9,326
  • 5
  • 21
  • 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
  • 168,305
  • 31
  • 280
  • 331