Skip to content
Advertisement

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’ instead of ‘MM/DD/YYYY h:mm:ss A’, but I expect there is

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 any method that

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 moment.js

MomentJS – How to get last day of previous month from date?

I’m trying to get last day of the previous month using: Where: But after using it returns date But last day of the 10’th month is 31. How can I solve i please? Many thanks for any help. Answer Simply add a endOf(‘month’) to your calls: var dateFrom = moment(dateFrom).subtract(1,’months’).endOf(‘month’).format(‘YYYY-MM-DD’); http://jsfiddle.net/r42jg/327/

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 Here’s a function that

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 hours between the two dates. How do

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 there are 3 complete months and one

Advertisement