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(),
};
CodePudding user response:
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(),
});