Search Posts

Category: momentjs

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 […]

How can I convert a date and time into a time only using angular-moment?

So I have dates like this: $scope.sample_time = “September 14th 2017, 1:00:00 pm”; And in my view, I want to only show the time like example 1:00 pm. Using angular-moment, I tried something like {{ sample_time | amParse:’HH:mm a’}} but I get 2017-09-14T06:00:00.000Z. Am I missing something here? Any help would be much appreciated. Source: AngularJS

Getting Moment JS to display time ago up to yesterday then start displaying a formatted date

Disclaimer: I’m very new to javascript (and angular). I’m trying to get momentjs to display the time from now up till yesterday. Once it’s been 3 days it would display the actual date. Example using random date (date diff will always be “today”): 10/10/17 at 6:41 pm (future) Tomorrow at 6:41 pm Today at 6:41 pm Yesterday at 6:41 pm 10/10/17 at 6:41 pm Not sure what other information I should provide but please ask […]