How do I change the language of moment.js?

I am trying to change the language of the date which is being set by moment.js. The default one is English, but I want to set the German language. These is what I tried: var now = moment().format(“LLL”).lang(“de”); It’s giving NaN. var now = moment(“de”).format(“LLL”); This isn’t even reacting. var now = moment().format(“LLL”, “de”); No … Read more

How do I format a date as ISO 8601 in moment.js?

This docs mention moment.ISO_8601 as a formatting option (from 2.7.0 – http://momentjs.com/docs/#/parsing/special-formats/), but neither of these work (even 2.7.0): var date = moment(); date.format(moment.ISO_8601); // error moment.format(date, moment.ISO_8601); // error (http://jsfiddle.net/b3d6uy05/1/) How can I get an ISO 8601 from moment.js? 9 Answers 9

Get the time difference between two datetimes

I know I can do anything and some more envolving Dates with momentjs. But embarrassingly, I’m having a hard time trying to do something that seems simple: geting the difference between 2 times. Example: var now = “04/09/2013 15:00:00”; var then = “04/09/2013 14:20:30”; //expected result: “00:39:30” what I tried: var now = moment(“04/09/2013 15:00:00”); … Read more

Moment JS – check if a date is today or in the future

I am trying to use momentjs to check if a given date is today or in the future. This is what I have so far: <script type=”text/javascript” src=”http://momentjs.com/downloads/moment.min.js”></script> <script type=”text/javascript”> var SpecialToDate=”31/01/2014″; // DD/MM/YYYY var SpecialTo = moment(SpecialToDate, “DD/MM/YYYY”); if (moment().diff(SpecialTo) > 0) { alert(‘date is today or in future’); } else { alert(‘date is … Read more

Get hours difference between two dates in Moment Js

I’m able to get the difference between two dates using MomentJs as follows: moment(end.diff(startTime)).format(“m[m] s[s]”) However, I also want to display the hour when applicable (only when >= 60 minutes have passed). However, when I try to retrieve the duration hours using the following: var duration = moment.duration(end.diff(startTime)); var hours = duration.hours(); it is returning … Read more

Moment.js transform to date object

Using Moment.js I can’t transform a correct moment object to a date object with timezones. I can’t get the correct date. Example: var oldDate = new Date(), momentObj = moment(oldDate).tz(“MST7MDT”), newDate = momentObj.toDate(); console.log(“start date ” + oldDate) console.log(“Format from moment with offset ” + momentObj.format()) console.log(“Format from moment without offset ” + momentObj.utc().format()) console.log(“(Date … Read more