0
나는 단계마다 시간 계산 얻으려고이를 위해 내가 할 :HealthKit이 잘못된 시간을 반환하는 이유는 무엇입니까?
func retrieveSteps(completion: @escaping (_ stepsCount: Double) -> Void) {
let stepsCount = HKQuantityType.quantityType(forIdentifier: .stepCount)
let date = Date()
let calendar = Calendar(identifier: .gregorian)
let newDate = calendar.startOfDay(for: date)
let predicate = HKQuery.predicateForSamples(withStart: newDate, end: date, options: [.strictStartDate])
var interval = DateComponents()
interval.hour = 1
let query = HKStatisticsCollectionQuery(quantityType: stepsCount!, quantitySamplePredicate: predicate, options: [.cumulativeSum], anchorDate: newDate, intervalComponents: interval)
query.initialResultsHandler = { query, result, error in
if let stats = result {
stats.enumerateStatistics(from: newDate, to: date) { statistics, _ in
if let quantity = statistics.sumQuantity() {
let steps = quantity.doubleValue(for: HKUnit.count())
print("Steps: \(steps) for: \(statistics.endDate)")
completion(steps)
}
}
}
}
HKHealthStore().execute(query)
}
을 그리고 그것을 실행할 때 잘못된 날짜 값을 얻는다. 예 :
Steps: 28.3782023430627 for: 2017-10-22 10:00:00 +0000
그러나 건강 앱에서는 시간이 11:58
입니다. 왜 제가 10:00
을 얻고 있습니까? 어떻게 개선 할 수 있습니까?
시, 분 및 초 형식을 지정하고 출력하십시오. – Lumialxk
@ Lumialxk하지만 어떻게 도움이 될까요? '10 : 00'과'11 : 58' 사이 - 2 hours =/ –
10 시가 시간대 일 뿐이라는 것이 궁금합니다. – Lumialxk