2012-10-04 85 views
0

是否有適用於所有區域格式的NSDateFormatter的日期格式。這可以工作:所有區域格式的NSDate格式

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

有人知道這個嗎?

回答

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