使用相同的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
如何知道停止使用我之前指定的日期格式?这样做是否安全可靠?