Add a duration to a moment (moment.js)

Moment version: 2.0.0 After reading the docs, I thought this would be straight-forward (Chrome console): var timestring1 = “2013-05-09T00:00:00Z”; var timestring2 = “2013-05-09T02:00:00Z”; var startdate = moment(timestring1); var expected_enddate = moment(timestring2); var returned_endate = startdate.add(moment.duration(2, ‘hours’)); returned_endate == expected_enddate // false returned_endate // Moment {_i: “2013-05-09T00:00:00Z”, _f: “YYYY-MM-DDTHH:mm:ss Z”, _l: undefined, _isUTC: false, _a: Array[7]…} … Read more

momentJS date string add 5 days

i have a start date string “20.03.2014” and i want to add 5 days to this with moment.js but i don’t get the new date “25.03.2014” in the alert window. here my javascript Code: startdate = “20.03.2014”; var new_date = moment(startdate, “DD-MM-YYYY”).add(“DD-MM-YYYY”, 5); alert(new_date); here my jsfiddle: http://jsfiddle.net/jbgUt/1/ How can i solve this ? I … Read more

Deprecation warning in Moment.js – Not in a recognized ISO format

I’m getting a warning that a value provided to moment is not in a recognized ISO format. I changed my variable today with the moment function and still it doesn’t work. Here’s the warning error: Deprecation warning: value provided is not in a recognized ISO format. moment construction falls back to js Date(), which is … Read more

How to use format() on a moment.js duration?

Is there any way I can use the moment.js format method on duration objects? I can’t find it anywhere in the docs and it doesn’t seen to be an attribute on duration objects. I’d like to be able to do something like: var diff = moment(end).unix() – moment(start).unix(); moment.duration(diff).format(‘hh:mm:ss’) Also, if there are any other … Read more