Calculate time difference in AngularJS

3

I have two variables, startTime (01:00:00 AM) and endTime (02:00:00 AM), I need to calculate the difference between one and another, how would I do this in the angular? I saw that there is Date.parse() , but I need to pass a date.

    
asked by anonymous 17.09.2015 / 07:50

2 answers

1

Example co filter:

generalFilters.filter('dateDiff', function () {
  var magicNumber = (1000 * 60 * 60 * 24);
  return function (toDate, fromDate) {
    if(toDate && fromDate){
      var dayDiff = Math.floor((toDate - fromDate) / magicNumber);
      if (angular.isNumber(dayDiff)){
        return dayDiff + 1;
      }
    }
  };
});


{{entry.toStr | dateDiff:entry.fromStr}} 

Credits: link

    
17.09.2015 / 13:44
1

See if any of these help you with what you need:

  • simple: link
  • with intervals: link
  • 17.09.2015 / 14:06