Skip to content Skip to sidebar Skip to footer

How To Make Js Date Respect Local Timezone?

I have the follow function that properly returns the date in the format required, but the value returned isn't respecting the local timezone. In this case, its 4 hours off. What wo

Solution 1:

Assuming that seconds is a unix epoch (UTC), you should just use

functiondate_str(seconds) {
    var dt = newDate(seconds*1000);
    console.log(dt);
    …

instead. The get…() methods will respect the local timezone. If you don't want that, you should use the getUTC…() equivalents.

Post a Comment for "How To Make Js Date Respect Local Timezone?"