How can i check if in another specific location now is daylight saving time using only native javascript?
For example, if i am based in Hong Kong, how can I use js to check if in New York or London currently is daylight saving time or not?
I have checked some posts like e. g. How to check if the DST (Daylight Saving Time) is in effect and if it is what's the offset?
It looks like it works if my base and target location are the same. But what if I want to check a different location, like ny/london?
My code:
function isDaylightSaving() {
const today = new Date();
const jan = new Date(today.getFullYear(), 0, 1);
const jul = new Date(today.getFullYear(), 6, 1);
return today.getTimezoneOffset() < Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
- If my local PC clock changes to Hong Kong time zone, it will always get false
- If my local PC clock changes to New York or London time zone, it will get true (given in April is daylight saving time)