最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Does dayjs handle DST timezones? - Stack Overflow

programmeradmin0浏览0评论

i need to handle DST timezones for a project. i was researching on google and a saw to github issue discussing where it said that dayjs was not handling these correctly. i tried to write some code and checking if it works with dayjs and it seems to be working, what should i do

const beforeDST_London = dayjs.tz("2024-03-30T12:00:00", "Europe/London");
        const afterDST_London = dayjs.tz("2024-04-01T12:00:00", "Europe/London");

        console.log("London Before DST:", beforeDST_London.format(), "UTC Offset:", beforeDST_London.utcOffset());
        console.log("London After DST:", afterDST_London.format(), "UTC Offset:", afterDST_London.utcOffset());

        const beforeDST_Sydney = dayjs.tz("2024-04-06T12:00:00", "Australia/Sydney");
        const afterDST_Sydney = dayjs.tz("2024-04-08T12:00:00", "Australia/Sydney");

        console.log("Sydney Before DST:", beforeDST_Sydney.format(), "UTC Offset:", beforeDST_Sydney.utcOffset());
        console.log("Sydney After DST:", afterDST_Sydney.format(), "UTC Offset:", afterDST_Sydney.utcOffset());

        const beforeDST_SP = dayjs.tz("2024-06-01T12:00:00", "America/Sao_Paulo");
        const afterDST_SP = dayjs.tz("2024-12-01T12:00:00", "America/Sao_Paulo");

        console.log("São Paulo June:", beforeDST_SP.format(), "UTC Offset:", beforeDST_SP.utcOffset());
        console.log("São Paulo December:", afterDST_SP.format(), "UTC Offset:", afterDST_SP.utcOffset());

        const beforeDST_India = dayjs.tz("2024-03-01T12:00:00", "Asia/Kolkata");
        const afterDST_India = dayjs.tz("2024-09-01T12:00:00", "Asia/Kolkata");

        console.log("India March:", beforeDST_India.format(), "UTC Offset:", beforeDST_India.utcOffset());
        console.log("India September:", afterDST_India.format(), "UTC Offset:", afterDST_India.utcOffset());

        const beforeDST_Cairo = dayjs.tz("2024-04-25T12:00:00", "Africa/Cairo");
        const afterDST_Cairo = dayjs.tz("2024-04-27T12:00:00", "Africa/Cairo");

        console.log("Cairo Before DST:", beforeDST_Cairo.format(), "UTC Offset:", beforeDST_Cairo.utcOffset());
        console.log("Cairo After DST:", afterDST_Cairo.format(), "UTC Offset:", afterDST_Cairo.utcOffset());

output of the code

发布评论

评论列表(0)

  1. 暂无评论