如何在 ionic 4 中从 google ft api 找到持续时间?

How to find duration from google fit api in ionic4?

我正在使用 google fit API 开发健身应用程序。我在其中计算距离、步数、卡路里和持续时间。除了持续时间之外,所有细节都已找到。如何使用 google fit api 找到持续时间?

提前致谢。

从 googleFit api,您会找到 startDateendDate

你必须得到时差并将它们相加。

首先导入googlefit服务:

import { GoogleFitService } from "../../core/services/google-fit.service";

在构造函数中声明它:

constructor(
 private googleFit: GoogleFitService
) { }

获取时长数据:

this.googleFit.query().then(res => {
 let totalDiff = 0;
 for (let i = 0; i < res.length; i++) {
   totalDiff =
     totalDiff +
     (res[i].endDate.getTime() -
       res[i].startDate.getTime()); // milliseconds
 }
 let seconds: any = (totalDiff / 1000).toFixed(0);
});