Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Aaron Beall
    Given a moment datetime format, like dateFormat = "MMM YYYY" is it possible to see what the parsed tokens are? For example with "MMM YYYY" I want to know it contains [month, year]
    I know I could use regexp against all the documented display format options
    Luis Ruiz
    hello friends, I'm comparing 2 dates that is composed in this way "dd-mm-yyyy" but moment is taking it as "mm-dd-yyyy", how can I configure it to read me in the order I need it? moment('08/05/2018', 'DD/MM/YYYY').isSameOrAfter('01/09/2018','DD/MM/YYYY');
    Brad Wertman
    import moment from "moment" in my React app. But I get an error "moment is not defined" when calling moment(). Is there something different I have to do to import moment vs every other node module I'm using?
    Sameer Siddiqui
    p0y0m0dt0h0m0s What is this time format called ?
    how i can convert dateTime in to above is there a func avail in moment ?
    Eder Gomez
    @bmwertman try import * as moment from "moment"
    Hey guys, anyone know if it's possible to show a separate month date if and only if the month changed in the time interval. ie Nov 11 - 17, but if a month changes during any week interval to then show the month? ie Nov 25 - Dec 1
    Joseph Maxim
    After adding moment.js client side in my react app my build load time tripled. is it not recomended to use clioentside?
    Raja Simon
    const result = currentTime.to(startTime); // In a day

    But I need to know exact days, hours, minutes, seconds like this 3, 18, 55, 60

    How do I achieve this? Hey by the way it's awesome library.

    Eder Gomez
    @rajasimon_gitlab you can use:
    moment(datetime).format("DD"); // result day
    moment(datetime).format("MM"); // result month
    moment(datetime).format("YYYY"); // result year
    moment(datetime).format("HH"); // result hour
    moment(datetime).format("mm"); // result minutes
    moment(datetime).format("ss"); // result seconds
    Raja Simon

    @Ederagp Thanks for your valuable answer but in your answer you used datetime to convert into desirable format. In my case I've two datetime and I need to know the time difference between two datetime in the format of ( years, months, dates, hours, minutes).

    const currentTime // Moment {_isAMomentObject: true, _i: "2018-11-24T10:00:00+05:30", _f: "YYYY-MM-DDTHH:mm:ssZ", _tzm: 330, _isUTC: false, …}
    const startTime // Moment {_isAMomentObject: true, _i: Fri Nov 23 2018 13:41:56 GMT+0530 (India Standard Time), _isUTC: false, _pf: {…}, _locale: Locale, …}

    Now that I know currentTime and startTime and I need to know the time difference and after digging through the momentJs docs I found that I can use to like this

    const result = currentTime.to(startTime) 

    but above code return In a day but what I want is years, months, hours, minutes, seconds Please help me to understand how to get this desirable format what I want.

    Eder Gomez
    @rajasimon since you know currentTime and startTime you can use, as explained in moment().diff():
    moment().diff(Moment | String | Number | Date | Array);
    Obtaining the difference can pass the unit of measurement required days, month, year, hour, minutes, seconds:
    a.diff(b, 'years');
    a.diff(b, 'days');
    Francis Rodrigues
    What's the best way to create a JS class/component (if use React) to reuse a moment instance?
    Is there a reason why the latest versions of spam-moment are not published to NPM?
    Joel Costa
    @mj1856 on moment/moment#1407 you said to talk with you so here it goes :)
    Is there any way to disable the warning during tests?
    Joel Costa
    Ok, found out how to do it right: moment.utc(dateString, moment.ISO_8601, true). Thanks :)
    Trent Jones
    Hi all, when I do something like this; moment.duration("P240M") it returns a duration object that has converted it to 20 years... Not wrong, but a little frustrating when I want .humanize() to return "240 months"... Am I missing something or my specific use-case is just a PITA?
    Daniel Jones
    Hey guys, I am parsing the string "1968-11-12T23:00:00.000Z" on two different devices, one is a mac and the other an Iphone and will say the day is 12th Nov 1968 while the other is Saying its the 13th, the locale on both appears to be GMT, what could be causing this?
    Sorry the locale is "en" on both
    Daniel Lizik
    anybody else have issues with jordan/amman timezone on safari?
    coming across a very strange bug
    Brad Wertman
    I'm having some trouble with date/time formatting. On my client I use moment(myDateObject).format('h:mm a') and check the output and I have what is expected, something like "7:53 am". I then use my socket.io connection to send that to my Raspberry Pi running on the same network locally and store it in a variable. When my client restarts it emits an event to my Rpi asking for the value to be returned. But what I get back isn't formatted as it was when I sent it. Instead it looks like "2019-02-08T12:53:22.000Z". Do I need to do something extra to grab the formatted date from Moment before sending it?
    kevin olson
    why does this give me March
    @acidjazz Because moment().format('M') returns 2 and months in javascript go from 0 to 11, so 2 represents March.
    Roy Hvaara
    Hi. Is there a way to check if a string is a valid iso8601 duration? (Eg. PT15M -> true, foo -> false)
    moment('2013W065', moment.ISO_8601).isValid(). Check docs to see supported strings.
    kevin olson
    @HeiVask so ill ask since it seems like i have to, why would moment accept a month numeric as not 0-11, but spit out a month numeric as 0-11
    Because moment uses tokens to create instances and format values. For get/set methods it uses real values.
    Arjun Biju
    hi guys
    any way to convert date time to "2018-10-04T11:54:07.000Z" format
    moment("2018-10-04 11:54:000").format("YYYY-MM-DDTHH:mm:ss.SSSSZ")
    results 2018-10-04T11:54:00.0000+05:30 this one
    but i need datetime to be in 2018-10-04T11:54:07.000Z format with z
    Arjun Biju
    some one help me out
    @Arrow66 AFAIK, Zulu is GMT, so can you append it simply as a string? like moment("2018-10-04 11:54:000").format("YYYY-MM-DDTHH:mm:ss.SSS[Z]") :s
    Ihsan Katmer
    hi everyone, i am trying to install moment.js I type npm install moment --save but after I the addition app crashes. any idea?
    Artem Biryukov
    Guys I have a problem with timezones on server
    I have users in my database with a field timezone which I'll utilize later
    The client sends hours in this format to server 19:30 then I take a user and his timezone and convert this time back to UTC
    Since my server is in UTC it's impossible to convert it to 16:30 I suppose
    Aubrey Quinn
    Hi all, can you help me out? When I call this function moment('01-01-2017', 'DD-MM-YYYY').startOf('month').week()
    I get different results even when the locale is the same
    in my project and browser I get 53 but in another browser i get 1 https://stackoverflow.com/questions/55724982/momentjs-returning-a-different-result-in-browser-than-in-karma-unit-test
    Eugene Serkin
    Hey guys, does anybody know, how to use moment-timezone with latest angular?
    Rodo Abad
    Is there a reason why if I do console.log(moment()) in a Node environment that it returns moment(<current data/time>) instead of executing like in a browser environment?
    Where it gives the actual Moment object?
    Hi all,
    i am using moment('2019-05-21T07:05:11.5685421-07:00').format('MM/DD/YYYY HH:MM:SS') function which is giving wrong time as '05/21/2019 08:05:11' even after changing time zone to (UTC-07:00)Mountain Time(US & Canada) . It should be 07:05:11. Please help me out to get the right time.
    Hi all,
    We working on accessibility fixes for client. Bug is role is missing for previous and next button of date picker. We using moment -2.8.3. Please let me know that above issue is fixed or not if fixed in which version.