Two-digit years with NSDateFormatter do not work

I have a 10.4 date formatter applied to an NSTextFieldCell. I call setTwoDigitStartDate: (tested with both the epoch date and the "referenced" date), but when I print a date with a two-digit year, it sets the year 0009 instead of 2009.

Title:

IBOutlet NSTextFieldCell *transactionDateField; // outlet *IS* set correctly in IB

      

Implementation:

- (void)awakeFromNib {
    NSDate *startDate = [NSDate dateWithTimeIntervalSinceReferenceDate:0];
    //NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:0];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateFormat setDateStyle:NSDateFormatterMediumStyle];
    [dateFormat setTwoDigitStartDate:startDate];
    [dateFormat setLenient:YES]; // tried with & without this
    [transactionDateField setFormatter:dateFormat];
}

      

Am I missing something obvious?

+2


source to share


1 answer


Try changing NSDateFormatterMediumStyle

toNSDateFormatterShortStyle



+1


source







All Articles