'javascript - check if daylight time is in effect for different timezone
There are many solutions available in javascript to check whether the date is in daylight or not [ How to check if the DST (Daylight Saving Time) is in effect and if it is what's the offset? ].
But that solutions work only when someone is in the same time zone where daylight effect is applicable, ex. Suppose my current browser (client) is in IST (Indian standard - where there is no daylight time change) and I want to check whether the date is in daylight or not for ET (Eastern time - where daylight is -5 and standard is -4). Above solution (from link) would give me correct result only if my systems time zone is in ET not IST.
How can I calculate it?
Solution 1:[1]
You can use luxon library to check is DST is active or not in particular area. all you need is timezone string and you can check is DST is active or not.
so first import DateTIme from luxon
import { DateTime } from "luxon";
then check if DST is active or not in the timezone
if (DateTime.local().setZone(timezone).isInDST) {
console.log("Dst is active in ", timezone)
}
else {
console.log("Dst is NOT active in ", timezone)
}
where timezone is the timezone you are looking for.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vipul Nikam |
