简体   繁体   中英

MomentJS: Finding Daylight savings transition dates for given year and time zone

Given: a date and its time zone in JS (in browser).

What is needed: Need to know whether the given date falls in the Daylight saving period of the given time zone or not.

One possible JS library to use is MomentJS. Is it possible to get Daylight saving moments for a given timezone?

In case, this solves my question, I tried to play with momentJS timezone here , but how do i interpret the following output:

moment.tz.add({
    "zones": {
        "CET": [
            "1 C-Eur CE%sT"
        ],
        "Etc/GMT": [
            "0 - GMT"
        ],
        "Etc/UTC": [
            "0 - UTC"
        ]
    },
    "rules": {
        "C-Eur": [
            "1916 1916 3 30 7 23 0 1 S",
            "1916 1916 9 1 7 1 0 0",
            "1917 1918 3 15 1 2 2 1 S",
            "1917 1918 8 15 1 2 2 0",
            "1940 1940 3 1 7 2 2 1 S",
            "1942 1942 10 2 7 2 2 0",
            "1943 1943 2 29 7 2 2 1 S",
            "1943 1943 9 4 7 2 2 0",
            "1944 1945 3 1 1 2 2 1 S",
            "1944 1944 9 2 7 2 2 0",
            "1945 1945 8 16 7 2 2 0",
            "1977 1980 3 1 0 2 2 1 S",
            "1977 1977 8 0 8 2 2 0",
            "1978 1978 9 1 7 2 2 0",
            "1979 1995 8 0 8 2 2 0",
            "1981 9999 2 0 8 2 2 1 S",
            "1996 9999 9 0 8 2 2 0"
        ]
    },
    "links": {}
});

You can just do this:

var tz = 'Europe/Paris';           // or whatever your time zone is
var dt = '2014-05-14 12:34:56';    // or whatever date/time you're working with
moment.tz(dt,tz).isDST()           // returns true in this case

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM