2

我有一个应用于 NSTextFieldCell 的 10.4 样式日期格式化程序。我调用 setTwoDigitStartDate: (尝试使用纪元日期和“参考”日期)但是当我输入具有两位数年份的日期时,它将年份设置为 0009 而不是 2009。

标题:

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

执行:

- (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];
}

我错过了一些明显的东西吗?

4

1 回答 1

1

试试改成NSDateFormatterMediumStyle这个NSDateFormatterShortStyle

于 2009-10-08T11:33:34.683 回答