NSDateFormatter不起作用的两位数年份

问题描述:

我有一个适用于NSTextFieldCell的10.4格式的日期格式化程序。我叫setTwoDigitStartDate:(同时与时代日期和“参考”日期试过),但是当我在以两位数年份的日期键入年设置为0009,而不是2009年NSDateFormatter不起作用的两位数年份

页眉的:

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

我失去了一些东西明显?

尝试改变NSDateFormatterMediumStyle这个NSDateFormatterShortStyle

+0

事实证明,setTwoDigitStartDate:只适用于具有两位数年份日期格式(NSDateFormatterShortStyle是一种这样的格式)。我认为你可以用这种方便的方法控制缩写长日期的输入,但是你不能。 – Matthew 2009-10-11 09:09:14