所以,我试图为日出和日落创建一个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