Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Time in Known Location with Known Offset and NO Daylight Saving Time

With the hundreds of posts concerning Javascript time questions, I’m certain this has been addressed but I’ve been through a couple of dozen posts so far and none answer my specific question. I know the offset (-7) and in this particular State in the USA (Arizona) there is NO DST. I just want to display the time in Arizona to any user. All the posts I’ve reviewed seem to imply that I need to use

return new Date().getTimezoneOffset();

from the local computer as part of my calculations but I’m not sure why that would be necessary? Would this be a viable solution?

const now = new Date();
        return {
            hour: (now.getUTCHours() -7)
            minute: now.getMinutes(),
        };

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You do not need to getTimezoneOffset, but you will need to handle the case when the hours are smaller than 7:

const now = new Date();
        console.log( {
            hour: ((now.getUTCHours() -7) % 24),
            minute: now.getMinutes(),
        });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading