Question

I have a 10.4 style date formatter applied to an NSTextFieldCell. I call setTwoDigitStartDate: (tried with both the epoch date and the "reference" date) but when I type in a date with a two digit year it sets the year to 0009 instead of 2009.

Header:

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?

Was it helpful?

Solution

Try changing NSDateFormatterMediumStyle to this NSDateFormatterShortStyle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top