NSDateFormatter在样式和格式之间交换

时间:2015-05-01 18:16:48

标签: objective-c cocoa cocoa-touch nsdateformatter

使用相同的NSDateFormatter并在样式和格式定义之间交换是否安全?例如:

NSDateFormatter *df = [NSDateFormatter new];
df.dateStyle = NSDateFormatterMediumStyle;
df.timeStyle = NSDateFormatterMediumStyle;
NSLog(@"Medium Style / Medium Time: %@", [df stringFromDate:[NSDate date]]);
df.dateFormat = @"MMM/d/yy hh:mm:ss";
NSLog(@"Custom Format: %@", [df stringFromDate:[NSDate date]]);
df.dateStyle = NSDateFormatterFullStyle;
df.timeStyle = NSDateFormatterNoStyle;
NSLog(@"Full Style/ No Time: %@", [df stringFromDate:[NSDate date]]); 
// ^-- how does it know to stop using the format I set before?

在最后一行中,NSDateFormatter如何知道停止使用我之前指定的日期格式?这样做是否安全可靠?

0 个答案:

没有答案