Skip to content

Tag: momentjs

Trying to add 5 years using moment

I am trying to add up to 5 years and each year it adds I am storing it to be displayed later. The output ends up being 2026 for all the outputs. I expecting to be: Answer Try the following: Just re-use the original moment object and modify it each time you want to use it.

Get the Second Highest Date in JavaScript/ES6

I have a problem getting the second highest date in ES6. I’m using moment.js too. Its supposed to be getting the id of 3. Answer You should use custom sort function as: There is no need to use find when you are reverseing the array and getting the index 1 from it. Note: I deliberately change the order o…

How to convert Moment.js moment to unix timestamp

I see a lot in the Moment.js documentation about getting a Moment from a Unix timestamp. However, I am trying to convert a Moment to a Unix timestamp, and I am not sure how to do that. This is how my moment looks: const myMomentObject = moment(str_time, ‘YYYY-MM-DD’); And I need to convert it to a…

invalid date printed

I am using moment from mongorc.js (reference: https://raw.githubusercontent.com/gabrielelana/mongodb-shell-extensions/master/released/mongorc.js) when executed this small snippet its printing “invalid date” But in Java: Prints Sun Nov 30 00:00:00 IST 2 Though may not be correct, I want not “…

How can I subtract 1 month using moment.js?

I want to subtract 1 month from a given date in (DD/MM/YYYY) format, but when I do that using moment.js, it gives me the result as 01/12/2020. How can I resolve this? Basically when I click on the left-arrow, the month should be subtracted by 1 every Answer How can I subtract one month using moment.js? tl,dr;…