我想根据出门时间和时间的差异来计算小时数。我想知道使用角度js实现它的可能方法。我需要它在小时:分钟:秒格式。以下是样本我的代码。
我的观点
<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>
我的javascript文件
$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) {
});
};
答案 0 :(得分:1)
在组件中:
SELECT *
FROM dbo.Grantinformation
WHERE HoldingOrganisationName = 'university of edinburgh'
标记:
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);
}