0

i have this code to show and hide a certain element at a given time:

function live(){
    var now = new Date();
    var elm = document.getElementById("live");
    if(now.getDay() == 0 && (now.getHours() >= 11 && now.getHours() <= 13)) {
        elm.style.display = 'block';
    } else{
        elm.style.display = 'none';
    }      
}

However, this wont work as expected because i need the time to be in Japan time, not the users time. How can i set the default timezone?

Thank you.

  • possible duplicate of [How to initialize javascript date to a particular timezone](http://stackoverflow.com/questions/15141762/how-to-initialize-javascript-date-to-a-particular-timezone) – Matt Johnson-Pint May 04 '14 at 19:58

1 Answers1

2

You can use timezone-js. Something like this could work:

var dt = new timezoneJS.Date("2014/05/04 10:10:30 +0000", 'Europe/London');
dt.setTimezone("Asia/Jakarta"); // You can check if they have Japan specific, if not you can probably create a new timezone with +0900
console.debug(dt); //return formatted date-time in asia/Jakarta

Some users have problems with this though and tend to use moment.js instead:

moment.tz("2014-04-05 11:55", "Tokyo").format(); // "2013-11-18T11:55:00-05:00"

Available timezones in moment.js

Jonast92
  • 4,964
  • 1
  • 18
  • 32