How to create a specific date in the distant past, the BC era.

Posted by alloy on Stack Overflow See other posts from Stack Overflow or by alloy
Published on 2010-04-27T07:46:23Z Indexed on 2010/04/27 8:53 UTC
Read the original article Hit count: 287

Filed under:
|
|

I’m trying to create a date in the BC era, but failing pretty hard. The following returns ‘4713’ as the year, instead of ‘-4712’:

  NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  NSDateComponents *components = [NSDateComponents new];
  [components setYear: -4712];
  NSDate *date = [calendar dateFromComponents:components];
  NSLog(@"%d", [[calendar components:NSYearCalendarUnit fromDate: date] year]);

Any idea what I’m doing wrong?

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about nsdate