Skip to content

Tag: momentjs

Don’t display time if midnight using Moment.js

How do I use http://momentjs.com/docs/ to only display the time if it is not midnight? For instance, please look at the first example below. A possible non-elegant solution would be to use JavaScript to check if the datetime trails with 00:00:00, and if so, provide a format string of ‘MM/DD/YYYY’ …

MomentJS set timezone without changing time

I’m trying to set the timezone for a date in moment.js without changing the time value I get a date in utc: and I need to set the time zone without changing the time. if I use date.utcOffset(moment().utcOffset()) it adds the offset: I could do but that seems like an inefficient way to do it. Is there an…

How to convert seconds to HH:mm:ss in moment.js

How can I convert seconds to HH:mm:ss? At the moment I am using the function below This works on chrome but in firefox for 12 seconds I get 01:00:12 I would like to use moment.js for cross browser compatibility I tried this but does not work What am I doing wrong? EDIT I managed to find a solution without mom…

How to get list of days in a month with Moment.js

Using Moment.js I would like to get all days in a month of specific year in an array. For example: any suggestions? I looked through Moment.js docs but couldn’t find anything. The closet I got was this: But this only return an int with total days for specific month not an array with each day. Answer Her…

Get hours difference between two dates in Moment Js

I’m able to get the difference between two dates using MomentJs as follows: 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: it is returning the current hour and not the number of ho…

Moment.js months difference

I’ve been using moment.js for a short while now, and it’s made date manipulation a lot easier but I have a specific case that is failing, and I can’t see why. When calculating the diff between today (31st October 2013) and the 1st February 2014, the months diff comes back as 2, although ther…