1

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.

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, after doing that i would only need to write below my code as normal?
I'm not sure, try it out.
timezone-js has been archived. Downwoting bececause of this, the answer has aged ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.