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
Tag: momentjs
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
Extract time from moment js object
How do i extract the time using moment.js? It should return “12:00:00 pm”. The string return will be passed to the timepicker control below. Any idea? Answer If you read the docs (http://momentjs.com/docs/#/displaying/) you can find this format: See JS Fiddle http://jsfiddle.net/Bjolja/6mn32xhu/
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 difference between 2 Dates in Years, Months and days using moment.js
How to get difference between 2 Dates in Years, Months and days using moment.js? For example the difference between 4/5/2014 & 2/22/2013 should be calculated as 1 Year, 1 Month and 14 Days. Answer Moment.js can’t handle this scenario directly. It does allow you to take the difference between two moments, but the result is an elapsed duration of time
Moment.js get the week number based on a specific day (also past years)
How could I get from moment JS the week number from a date in the past only from a moment formatted object from a day selected? Answer According momentjs docs: Because different locales define week of year numbering differently, Moment.js added moment#week to get/set the localized week of the year. The week of the year varies depending on which day
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