그래서 일출과 일몰에 NSDate
개체를 만들려고합니다. 나는 NSDatePicker
에 기초한 날짜를 얻었고, 나는지도로부터 좌표를 얻었고, 나는지도에서 GPS로부터 시간대를 얻는다.NSDate 및 NSDateformatter 잘못된 출력
은 내가 NSDate
객체를 얻기 위해이 코드를 사용 : https://github.com/MosheBerman/KosherCocoa-legacy 이 하나의 좌표 얻을 : https://github.com/digdog/MapKitDragAndDrop 그리고 좌표에 따라 시간대를 얻을이 하나 https://github.com/Alterplay/APTimeZones합니다.
지금 내 실제 위치는 로스 앤젤레스에 있으며, 일출과 일몰은 테스트를 위해 덴마크에서 돌아 왔습니다.
-(NSString *)sunriseDate{
//Create the GeoLocation based on 'latitude' and 'longitude' (getting the from MapKitDragAndDrop) and 'location.timeZone' (getting that from APTimeZones).
GeoLocation *position = [[GeoLocation alloc] initWithName:@"position" andLatitude:latitude andLongitude:longitude andTimeZone:location.timeZone];
AstronomicalCalendar *astronomicalCalender = [[AstronomicalCalendar alloc] initWithLocation:position];
//daysBetween is the value from NSDatePicker
astronomicalCalender.workingDate = [NSDate dateWithTimeIntervalSinceNow:kSecondsInADay*[self daysBetween]];
NSDate *sunriseDate = [astronomicalCalender sunrise];
NSLog(@"Sunrise time: %@", sunriseDate);
//This spits out: Sunrise time: 2014-03-05 06:09:53 AM +0000 which is the right time.
NSDateFormatter *sunriseTime = [[NSDateFormatter alloc] init];
[sunriseTime setDateFormat:@"HH:mm:ss"];
NSString *sunriseString = [sunriseTime stringFromDate:sunriseDate];
NSLog(@"Sunrisestring: %@", sunriseString);
//This spits out: 10:09:53 PM.
return sunriseString;
}
왜 이런 일이 일어날까요?
나는 아무것도 찾지 못했고 나는 찾고 있었다. 나는이 대답에서 아무것도 얻을 수 없었다. 어떻게 표시할지 그리고/또는 iPhone이있는 시간대를 제외하고. 만약 당신이 내 자신의 검색 이후로 이야기하고있는 스레드의 방향으로 나를 가리킬 수 있다면. 짧은되었습니다. (EEE는 하루 동안, zzzz는 시간대를 기준으로 함) – 4FunAndProfit