Search Posts

Category: momentjs

How i get days accurately in Moment.js

This is my code for getting days difference from given dates. I need the days accurately, Here my correct days different is ‘2’ but i am getting 1. i am using moment.js for this operation in angular. This is not taking time . I need time to take for getting result. I am using this code in calendar so i need to take time too. var startdate=new Date(‘2017-12-30 06:00:00’); var enddate=new Date(‘2018-01-01 01:00:00’); var diff= […]

Do I need momentJS if I’m using moment-with-locales?

Right now I’m adding scripts in my project in following sequence:[ + “/scripts/css/xxx.css”, + “/scripts/js/xxx.min.js”, + “/scripts/js/polyfills.min.js”, + “/scripts/js/jquery.min.js”, currHost + “/components/lib/lodash.min.js”, + “/scripts/js/moment.min.js”, + “/scripts/js/angular.min.js” ], function() {[ + “/scripts/js/angular-messages.js”, + “/scripts/js/angular-ui-router.js”, + “/scripts/js/angular-animate.js”, currHost + “/components/lib/toaster.min.js”, + “/scripts/js/ui-grid.min.js”, currHost + “/components/lib/defiant.min.js”, + “/scripts/js/xxx-ui.js”, currHost + “/components/lib/polyfill-resize.js”, currHost + “/components/lib/draggable-rows.js”, currHost + “/components/lib/moment-with-locales.js”, ], function() {[ currHost + “/components/common.bundle.js”, currHost […]

Display dates from array in a table

I have a problem where i want create an array of dates using moment.js and then display the contents of the array of dates in a table. <table border=”1″> <tr ng-repeat=”days in arr track by $index”> <td ng-repeat=”d in days track by $index”> {{d}} </td> </tr> </table> Dates are created using moment and pushed to an array var date = moment(), begin = moment(date).startOf(‘week’).isoWeekday(1); var arr = []; for (var i=0; i<35; i++) { arr.push(begin.format(‘D’)); […]

Optimize the JS Function to filter the data based on Month

Currently, I have written below function to filter the items based on the month and return in Array and I have used below login. Can someone help is there any way I can filter even more easily using datejs or moment js using for loop in more efficient way Here I am getting date in the format of 2/Jan/17 and filtering based on includes method Thanks in advance!! Javascript function getMonthlyCount() { return yearlyExecution() .then(function(myitems) […]

What is the most effective way to copy time (hh, mm) from one datetime to another?

I’m trying to write a calendar with timepicker, so that when you change the date, the time stays the same. Both fields (calendar and time) in html use the same variable (vm.inputDate) and I don’t want to change that. Right now I have this function, that triggers on date change: vm.keepTimeUnchanged = function(changedDateTime, oldDateTime) { var hours = oldDateTime.getHours(); var minutes = oldDateTime.getMinutes(); if (!moment(vm.inputDate).isSame((changedDateTime), ‘day’)) { vm.inputDate = changedDateTime; vm.inputDate.setHours(hours, minutes); } return vm.inputDate; […]

Angular Moment Date Picker date time inconsistency

I have an angular 1.5 application where i make use of a moment datepicker library from here : angular moment date picker Everything has worked well until recently when we realized that the date pickers rendered dates wrongly across different user pc’s .It appears this may have something to do with how JavaScript handles time zones: In the image below October 1, 2017 is actually a Sunday but the date picker renders it as a […]

Next Page »