Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    sasial
    @sasial-dev
    Yes, this was added at the start of the script.
    const dayjs = require('dayjs')
    // Load DAYJS Plugins
    var relativeTime = require('dayjs/plugin/relativeTime')
    var utc = require('dayjs/plugin/utc') 
    var timezone = require('dayjs/plugin/timezone') // dependent on utc plugin
    dayjs.extend(relativeTime)
    dayjs.extend(utc)
    dayjs.extend(timezone)
    sasial
    @sasial-dev
    Don't worry about this, I'll use a different library, as after looking at the d.ts, it doesn't work for the library I'm using
    iamkun
    @iamkun
    Better check your vscode settings.
    Matt Haggard
    @iffy
    How do I retain the offset that was present when I parsed a timestamp? I want to display the timestamp with the original offset regardless of my local offset.
    let a = dayjs("2000-01-01 01:02:03+07:00")
    let b = a.add(1, 'day');
    // what do I do here?
    b.format("YYYY-MM-DD HH:mm:ssZ") === "2000-01-02 01:02:03+07:00"
    John Winston
    @winston0410
    Hi, is it possible to get the date of all Saturday of a month in dayjs?
    2 replies
    RayTien
    @Ray0907
    Can I translate to traditional chinese?
    Kirstin Walsh
    @pyxis828

    I am having some timezone issues....I have some date/time objects that I have to convert from UTC time to EST. I need to compare the current time to a string that I convert into a date object. I can't seem to find a way to compare the 2 date/times where the comparison returns correctly. When the string that I have converted into a date object is before the current time, it is returning false (not before the current time). I don't understand why this is happening, unless it is because there is no timezone attached to the converted string date. When I try to attach a timezone to it, it doesn't seem to work - or it is attaching the GMT timezone instead of EST timezone. I am not sure what I am doing wrong.

     let deploymentTime = dayjs.tz(`${parseInt(month)+1}/${date}/${year} ${deployHour}:${dataObj.minute.value} ${period}`, "America/New_York").format('M/D/YYYY h:mm a');
                    let otherTime = dayjs(`${parseInt(month)+1}/${date}/${year} ${deployHour}:${dataObj.minute.value} ${period}`).format('M/D/YYYY h:mm a');
                    console.log(dayjs().tz("America/New_York").toString())
                    console.log("DEPLOYMENT time: " +deploymentTime.toString());
                    console.log("other time: " +deploymentTime.toString());
                    console.log(dayjs().tz("America/New_York").isBefore(deploymentTime, 'minute'))
                    console.log(dayjs().tz("America/New_York").isBefore(otherTime, 'minute'))

    logs out:

    [0-0] Tue, 08 Dec 2020 16:58:53 GMT
    DEPLOYMENT time: 12/8/2020 4:00 pm
    other time: 12/8/2020 4:00 pm
    [0-0] true
    [0-0] false
    Kirstin Walsh
    @pyxis828

    @iamkun I am still striggling to get time in my local timezone. The system I am running in is running in UTC, but I need to convert the time to my local time of EST. I have tried setting the default tiemzone to EST, but when I call dayjs().tz() or dayjs().tz().local() it gives me the same time as just calling dayjs(). How do I convert time from UTC to EST?

    dayjs.extend(utc)
     dayjs.extend(timezone)
     dayjs.extend(customParseFormat)
     dayjs.tz.setDefault("America/New_York")
    console.log("date: " +dayjs().toString())
    console.log("date with timezone: " +dayjs().tz().toString())
    console.log("date with local timezone: " + dayjs().tz().local().toString())

    logs out:

    date: Tue, 19 Jan 2021 16:53:10 GMT
    [0-0] date with timezone: Tue, 19 Jan 2021 16:53:10 GMT
    [0-0] date with local timezone: Tue, 19 Jan 2021 16:53:10 GMT
    Eric Guan
    @guanzo
    need help with getting the nth weekday. like 4th friday of the month, 2nd sunday of the month, etc.
    tried this but not working
    // daynum is 0 to 6, 0 = sunday, 6 = saturday
    // to get the 2nd friday of the current month, call getNthDayOfWeek(5, 2)
    export function getNthDayOfWeek (dayNum, nth) {
        const date = dayjs().startOf('month').add(nth - 1, 'week').day(dayNum)
        return date.toDate()
    }
    the attempted logic is "get the nth week and then the specified day of that week"
    Eric Guan
    @guanzo
    date manipulation hurts my brain
    Eric Guan
    @guanzo
    This message was deleted
    Karo
    @Karo70968982_twitter
    Hi, is it possible to use Airbnb react-dates with dayjs?
    Henri Toivar
    @henritoivar
    Hi Guys,
    I wanted to share something me and my buddies created using dayjs. It's an open-source, serverless, free, no-signup invoice management solution.
    You can check it on ProductHunt: https://www.producthunt.com/posts/serverless-invoices and Github: https://github.com/mokuappio/serverless-invoices
    Hopefully some of you can use it as a starter kit.
    I would love to hear your feedback!
    Thanks
    1 reply
    Eugene Serkin
    @jeserkin
    Good day. I am having a odd issue with dayjs. To be more specific, when I call dayjs('17.04.2021', 'DD.MM.YYYY'); on dayjs website it works perfectly fine. When I run same thing inside my app, I do get Dayjs object, but it has
    image.png
    antch
    @antch
    Hi, I'd just like to verify that this is a bug before submitting an issue.
    dayjs(new Date(), 'America/Puerto_Rico').startOf('y').format(); // 2021-01-01T00:00:00-05:00 -- wrong
    dayjs(new Date(), 'America/Puerto_Rico').startOf('y').utc().format(); // 2021-01-01T05:00:00Z -- wrong
    dayjs(new Date()).tz('America/Puerto_Rico').startOf('y').format(); // 2021-01-01T00:00:00-04:00 -- correct
    dayjs(new Date()).tz('America/Puerto_Rico').startOf('y').utc().format(); // 2021-01-01T05:00:00Z -- wrong
    This is a TZ with an offset of -4:00 and no DST
    looks like probable issues with both timezone and utc plugins...
    Soham Ashodiya
    @sohamashodiya

    Hi, can someone help me with the validation of ISO dates:

    console.log(
      "ISO FORMAT?",
      dayjs(
        "2021-04-28T00:00:00.000+0000",
        "YYYY-MM-DDTHH:mm:ss.SSSZZ",
        true
      ).isValid()
    );

    Is coming back as false...even though I believe the format string is correct.

    johnm
    @miaoz2001

    Hi, I am having an error when do jest test, saying TypeError: dayjs is not a function
    my code is as

      import dayjs from "dayjs";
    
      let due_future = dayjs().add(30, "days").toDate();

    the code is quite simple..
    and below is my jest.config.js

    module.exports = {
        verbose: true,
        resolver: 'jest-svelte-resolver',
        transform: {
            '^.+\\.(svelte)$': ['svelte-jester', {
                compilerOptions: { format: 'cjs' },
                debug: false
            }],
            '^.+\\.js$': 'babel-jest'
        },
        moduleFileExtensions: ['js', 'svelte', 'jsx', 'ts'],
        setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"],
        transformIgnorePatterns: [
            "node_modules/(?!(svelte-calendar|svelte-routing|svelte-spa-router|@smui|@material)/)"
        ],
        moduleNameMapper: {
            "^.+\\.(css|less|scss)$": "babel-jest",
        },
    }
    Philip Rueker
    @prueker
    Is there an easy way to use Duration by exclude certain days of the week from the calculation (aka only count duration between two dates, but exclude weekend days)?
    daghendrik
    @daghendrik
    Hi, is there an equivalent of moment().isDST(); in DayJS ?
    Thái Huy Nhật Quang
    @thaihuynhatquang
    Hi @iamkun, how can I config antd-dayjs-webpack-plugin to craco.config.js? it seems doesn't work :(
    Rajasegar Chandran
    @rajasegar
    Hello everyone, I wrote a codemod to migrate from Moment to Day.js
    https://github.com/rajasegar/moment-dayjs-codemod
    Appreciate any feedbacks / comments.