2011-10-01 95 views

回答

3

您可以在NSDateFormatter

- (NSDate *)dateFromString:(NSString *)string 

試試這個方法的例子

dateFormatter = [[NSDateFormatter alloc] init]; 

NSLocale *en_US = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; 
[dateFormatter setLocale:en_US]; 
[en_US release]; 

[dateFormatter setDateFormat:@"MM/dd/yyyy h:mm:ss a"]; 
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:-60*60*7]]; 
NSDate *date = [dateFormatter dateFromString:dateString]; 

[dateFormatter release]; 
+0

重要提示:如果您想要的日期始終顯示相同,[明確指定的本地格式的](http://stackoverflow.com/questions/6613110/what-is-the-best-way-to-deal-with-the-nsdateformater-locale-feature)。 –