Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angularjs使用momentjs获取总小时数_Javascript_Angularjs - Fatal编程技术网

Javascript Angularjs使用momentjs获取总小时数

Javascript Angularjs使用momentjs获取总小时数,javascript,angularjs,Javascript,Angularjs,我有10条时间记录。我想用momentjs得到总小时数 这是我的密码 总小时值 00:47:21 00:00:25 00:00:08 00:00:03 00:00:37 16:12:12 04:44:22 01:39:03 00:01:58 16:17:29 我的控制器 vm.tth = 0; function getFirst() { dataservice.getUserProfile(vm.userId).then(function (data) { vm.userlis

我有10条时间记录。我想用momentjs得到总小时数

这是我的密码

总小时值

00:47:21
00:00:25
00:00:08
00:00:03
00:00:37
16:12:12
04:44:22
01:39:03
00:01:58
16:17:29
我的控制器

vm.tth = 0;

function getFirst() {

  dataservice.getUserProfile(vm.userId).then(function (data) {
    vm.userlistData2 = data;
    imageservice.getCurrentImage(vm.userlistData2.user_id).then(function (data) {
      vm.photo = data;
    });

    dataservice.getUserAttendance(vm.userlistData2.user_id).then(function (data) {

      vm.attendance = data;

      for( var x=0; x < vm.attendance.length; x++){

        vm.tth += moment.duration(vm.attendance[x].totalHrs);
        console.log(moment(vm.tth).format('HH:mm:ss'));

      }
      return vm.attendance;

    });
  });
}
vm.tth=0;
函数getFirst(){
getUserProfile(vm.userId)。然后(函数(数据){
vm.userlistData2=数据;
imageservice.getCurrentImage(vm.userlistData2.user\u id)。然后(函数(数据){
vm.photo=数据;
});
dataservice.getUserAttention(vm.userlistData2.user\u id)。然后(函数(数据){
vm.attention=数据;
对于(var x=0;x
输出错误:


您获得该输出的原因有两个:

  • 您正在将
    tth
    转换为矩。您应该将其转换为持续时间
  • 你的总小时数超过了24小时,因此他们得到了调整(小时数%24)。在这种情况下,您可能希望显示天数和小时数
  • 以下是获得输出的两种方法(检查console中的最后几行以了解两种输出之间的差异):

    注意:由于您的问题与angularjs无关,所以我将展示简单的JS代码

    var考勤=[
    '00:47:21',
    '00:00:25',
    '00:00:08',
    '00:00:03',
    '00:00:37',
    '16:12:12',
    '04:44:22',
    '01:39:03',
    '00:01:58',
    '16:17:29'
    ];
    var-tth=0;
    对于(变量x=0;x>“+d.days()+”+d.hours()+”:“+d.minutes()+”:“+d.seconds());
    console.log(矩(tth).format('HH:mm:ss')+',小时数超过24小时+parseInt(d.asHours())+':'+d.minutes()+':'+d.seconds());
    }

    获得该输出有两个原因:

  • 您正在将
    tth
    转换为矩。您应该将其转换为持续时间
  • 你的总小时数超过了24小时,因此他们得到了调整(小时数%24)。在这种情况下,您可能希望显示天数和小时数
  • 以下是获得输出的两种方法(检查console中的最后几行以了解两种输出之间的差异):

    注意:由于您的问题与angularjs无关,所以我将展示简单的JS代码

    var考勤=[
    '00:47:21',
    '00:00:25',
    '00:00:08',
    '00:00:03',
    '00:00:37',
    '16:12:12',
    '04:44:22',
    '01:39:03',
    '00:01:58',
    '16:17:29'
    ];
    var-tth=0;
    对于(变量x=0;x>“+d.days()+”+d.hours()+”:“+d.minutes()+”:“+d.seconds());
    console.log(矩(tth).format('HH:mm:ss')+',小时数超过24小时+parseInt(d.asHours())+':'+d.minutes()+':'+d.seconds());
    }

    天哪!非常感谢你,兄弟,终于了解了它的工作原理。天哪!非常感谢你,兄弟,终于了解了它的工作原理。