문제

플로트를 nsdate로 변환하고 싶습니다

이것을 사용하여 nsdate를 플로트로 변환했습니다.

// Turn the date into Integers 
NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];  
NSCalendarUnit unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;  
NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:nsdate_wakeTime];  
NSInteger hour = [dateComponents hour];  
NSInteger min = [dateComponents minute];  

//Convert the time in 24:60 to x.x format.
float myTime = hour + min/60; 

수학 일이 끝난 후 MyTime 변수에서 수행하는 일은 동일한 플로트 형식으로 다른 시간을 얻습니다.

플로트를 nsdate로 어떻게 바꾸나요?

감사!

도움이 되었습니까?

해결책

계산 된 시간을 몇 초로 변환하면 (따라서 MyTime * 60) dateWithTimeIntervalSinceReferenceDate: 다시 돌아 가기 위해 NSDate. 당신이하고있는 수학에서, 여기서 참조 된 날짜는 문제의 날에 대한 00:00 인 것처럼 보입니다. Jason이 언급했듯이, 당신이 성취하려는 일을하는 더 좋은 방법이있을 것입니다.

또한 실제로 분을 원하는 경우 "MyTime"계산을 60.0으로 나누어야합니다. 샘플 코드는 60 미만의 정수 값을 정수 값 60으로 나누고 있으며, 이는 항상 0입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top