Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Scott O'Toole
    This is probably related... now I'm just looking for a solution: As of version 2.10.0, the moment global is no longer available if a module system is detected. This was previously working in 2.9.0.

    Hey, I have a small problem with formatting output moment string what I want to do is
    1) parse string I have (always like this: 2013W06 # Basic (short) week only)
    2) substract 1 week
    3) display in same format

    Is there anything better than doing it parsed.format('YYYY[E]w') ?

    hello i have the follow timestring (00:15:00, HH:mm:ss) and i want to get (15 min) how can i do that?
    Eder Gomez
    @Franky82dev you have to format moment().format("mm") //minutes
    @Ederagp thx for help
    Hi there
    My input is 2018-05-31T21:10:54.010Z, i want to convert this into PDT time-zone
    let formattedDate = moment.tz("2018-05-31T21:10:54.010Z", "America/Los_Angeles");
    tooltipValue = formattedDate.format("MM/DD/YYYY [at] HH:mm:ss z");
    any help would be highly appreciated, thank you!
    Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.

    Hey, I have a problem with .diff(). following tests are failing

    t.is(moment([2019, 9, 30]).diff(moment([2018, 7, 31]), 'months', true), 14); // returns 13.96774193548387
    t.is(moment([2019, 2, 28]).diff(moment([2018, 8, 30]), 'months', true), 6); // returns 5.933333333333334

    I found something similar in the issue moment/moment#3029. Any clue why this returns the wrong diff? Do I miss something? thanks (using version 2.22.2)

    Tiago Magalhães
    Hello.. Can I make a feature request (because may not be an issue) by opening an issue?
    Ryan Ragle
    Are moment timestamps always in utc?
    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