Skip to content
Advertisement

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 of the

moment.js returns invalid Date for moment (String, string)

Wants to compare the timestamp. Tried lots of ways but it is throwing an Invalid Date error. The variables startDate /endDate/testDate returns a same timestamp format in ‘DD.MM.YYYY HH:MM:ss’ i.e. ‘21.12.2021 08:29:00’ Also tried using isBetween() function. But for all the conditions it is throwing result as false. please correct me. Answer From https://momentjs.com/docs/#/parsing/string-format/ momentjs docs screenshot MM in HH:MM:ss

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 Unix timestamp. Answer Unix

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 “Invalid date” to be printed. Where did I go wrong? Answer I have hard coded the date value and it worked:

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; initial answer: Here’s

how to convert minutes to HH:mm with moment plugin

I have 2 timestamps and i already calculated the time difference in minutes with moment plugin. Now i want to convert the minutes to HH:mm. What i am doing wrong? Answer Since you have not specified what is the error, I’m assuming you are leaving the dependencies required for duration method. The moment-duration-format depends on moment, so you should require

Advertisement