Skip to content

Tag: momentjs

Moment.js always returns ‘a few seconds ago’

From the docs: “To get the current date and time, just call moment() with no parameters. This is essentially the same as calling moment(new Date()). Note: From version 2.14.0, moment([]) and moment({}) also return now. They used to default to start-of-today before 2.14.0, but that was arbitrary so it wa…

Adding minutes to datetime in momentjs

I need to add the variable secondsToMinutes to the startdate. secondsToMinutes is “3:20” startDate = “2:00 PM” endDate should equal “2:03:20 PM”. I’ve tried a number of ways and get errors each and every time. Date shows up as invalid date. Answer moment().format(&#82…

Using moment to format time in relation to now

I’m trying to display a date like “a few seconds ago”, “10 minutes ago”, “a day ago” with momentjs in the browser. date returns “in 14 minutes” NOT “14 minutes ago”. How can I fix this? Answer Because you would have been comparing it in that wa…

Moment.js compare two date thrown a warning

I have created a simple app, which need a date comparison. I used Moment.js, and I have tried on answer on this question: Compare two dates in JS Moment js date time comparison How to compare only date in moment.js But all of them not working for me. and now I use this code: But in the console it’s thro…

How to parse given date string using moment.js?

I want the following date string to be formatted using moment.js but it gives invalid date. How to parse it correctly or is there any other way to do so? Answer Just use pattern as second parameter in moment function more here in the docs: http://momentjs.com/docs/#/parsing/string-format/