javascript - Calculating hours difference between two dates in AngularJS -
this question has answer here:
- how subtract 2 angularjs date variables 7 answers
i've got template looks this:
<tr ng-repeat="task in tasks" class="thumbnail"> <td ng-model="task.id">{[{ task.id }]}</td> <td ng-model="task.time_start">{[{ task.time_start | date : 'mmm d, y hh:mm' }]}</td> <td ng-model="task.time_stop">{[{ task.time_stop | date : 'mmm d, y hh:mm' }]}</td> <td>[here want time difference]</td> <td><button ng-click="edit(task)">update</button></td> </tr> and want count hours difference between task.time_stop , task.time_start. there anyway "live", in template?
use moment library this:
moment.utc(moment(task.time_stop.diff(moment(task.time_start))).format("mm") you can wrap call in function:
$scope.timediff = function(start, end){ return moment.utc(moment(end).diff(moment(start))).format("mm") } or better create factory this... make reusable
ps: update code call $scope.timediff display time difference:
<td>timediff(task.start,task.end )</td>
Comments
Post a Comment