所有区域格式的NSDate格式

时间:2012-10-04 15:47:54

标签: iphone ios localization nsdate

NSDateFormatter是否有适用于所有区域格式的日期格式。这可以工作:

NSDateFormatter *dateformat = [[NSDateFormatter alloc]init];
[dateformat setDateFormat:@"?"];
NSDate *testDate = [dateformat dateFromString:@"%@ %@",dateStr,timeStr];
NSLog(@"%@",testDate);

有人知道吗?

1 个答案:

答案 0 :(得分:0)

您可以使用特殊格式属性dateStyletimeStyle。它们适用于所有区域格式,但您必须自己找出适合您特定情况的格式。日期和时间的输入相同。例如:

formatter.dateStyle = NSDateFormatterMediumStyle;
formatter.timeStyle = NSDateFormatterMediumStyle;

以下是可用的内容:

typedef NS_ENUM(NSUInteger, NSDateFormatterStyle) {    // date and time format styles
    NSDateFormatterNoStyle = kCFDateFormatterNoStyle,
    NSDateFormatterShortStyle = kCFDateFormatterShortStyle,
    NSDateFormatterMediumStyle = kCFDateFormatterMediumStyle,
    NSDateFormatterLongStyle = kCFDateFormatterLongStyle,
    NSDateFormatterFullStyle = kCFDateFormatterFullStyle
};
相关问题