2

我正在编写一个应用程序,该应用程序在夏至和冬至都利用太阳队的位置。虽然那里有很多数据表,但我想知道是否有任何标准的 iOS 组件可用于计算或检索至日日期,而无需嵌入然后查找数据。

4

1 回答 1

3

从评论中获取建议,以下是我实施的以从儒略日期获得小时和分钟的公历日期。

- (NSDate *) dateFromJulianDate:(double)julianDate
{
  NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  NSDate *gregorianDate;

  double datePart = floor(julianDate);
  double timePart = julianDate - datePart + 0.5;

  // Really the next calendar day?
  if (timePart >= 1.0) {
    timePart = timePart - 1.0;
    datePart = datePart + 1;
  }

  double l = datePart + 68569;
  double n = floor (4 * l / 146097);
  l = floor(l) - floor((146097 * n + 3) / 4);
  int year = floor(4000 * (l + 1) / 1461001);
  l = l - (floor(1461 * year / 4)) + 31;
  int month = floor(80 * l / 2447);
  int day = l - floor(2447 * month / 80);
  l = floor(month / 11);
  month = floor(month + 2 - 12 * l);
  year = floor(100 * (n - 49) + year + l);
  double hour = timePart * 24.0;
  double minutePart = hour - floor(hour);
  hour = floor(hour);
  double minute = minutePart * 60;
  NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
  [dateComponents setYear:year];
  [dateComponents setMonth:month];
  [dateComponents setDay:day];
  [dateComponents setHour:hour];
  [dateComponents setMinute:minute];
  [dateComponents setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  gregorianDate = [gregorianCalendar dateFromComponents:dateComponents];

  return [gregorianDate copy];
}
于 2013-05-09T04:38:28.107 回答