Javascript 如何获得角度js中的时间差?
我想根据超时和超时的差值计算加班时间。我想知道使用angular js实现加班的可能方法。重要的是,我需要小时:分钟:秒格式。以下是我的代码示例 我的看法Javascript 如何获得角度js中的时间差?,javascript,php,angularjs,laravel,Javascript,Php,Angularjs,Laravel,我想根据超时和超时的差值计算加班时间。我想知道使用angular js实现加班的可能方法。重要的是,我需要小时:分钟:秒格式。以下是我的代码示例 我的看法 <table class="row-border hover table table-bordered cb-data-table"> <tr> <th>In Time</th> <th>Out Time</th>
<table class="row-border hover table table-bordered cb-data-table">
<tr>
<th>In Time</th>
<th>Out Time</th>
<th>OT Hours</th>
</tr>
<tr ng-show="!dailyAttendances.length">
<td colspan="3" style="text-align: center">~ No Any Records ~</td>
</tr>
<tr ng-repeat="dailyAttendance in dailyAttendances" >
<td>@{{ dailyAttendance.in_time}}</td>
<td>@{{ dailyAttendance.out_time}}</td>
<td></td>
</tr>
</table>
在组件中:
在标记中:
{{timeDuration(dailyAttendance.in_time,dailyAttendance.in_time)}
你怎么知道是上午还是下午?{{dailyAttendance.out\u time-常规办公室\u end\u time}@shih因为它不起作用,所以我试过。@ramesh in\u time总是我。
$scope.loadAllDailyAttendance = function () {
$scope.dailyAttendances = {};
$http({
method: "GET",
url: "/attendance/loadAllDailyAttendance",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
}).then(function successCallback(response) {
$scope.dailyAttendances = response.data;
console.log(response.data);
}, function errorCallback(response) {
});
};
timeDuration(endTime: string, startTime: string): string {
const endDate = new Date(endTime).getTime();
const startDate = new Date(startTime).getTime();
const time = endDate - startDate;
return this.mlsecondsToTime(time);
}
private mlsecondsToTime(milliSec: number): string {
function pad(n: number): string {
const z = 2;
return ('00' + n).slice(-z);
}
let x = milliSec / 1000;
const seconds = x % 60;
x /= 60;
const minutes = Math.floor(x % 60);
x /= 60;
const hours = Math.floor(x % 24);
return pad(hours) + ':' + pad(minutes) + ':' + pad(seconds);
}
<td> {{timeDuration(dailyAttendance.in_time, dailyAttendance.in_time)}} </td>