我有一個NSString是05/08/2014。我想將其轉換爲NSDate。不過,我也需要及時補充,因此所得到的NSDate是這樣的:轉換NSString到NSDate,添加時間
Thu, 8 May 2014 00:00:00 -0500
的時間並不重要,我只需要在指定的時區顯示午夜。
我曾嘗試:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss zzz"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:textdate.text];
[dateFormatter release];
NSLog(@"%@", dateFromString);
但日回來爲(空)。
您爲dateformatter設置的格式與您告訴它解析的日期格式不匹配。 – Logan
@Logan那麼,採取字符串05/08/2014並將其轉換爲NSDateFormatter格式的好方法是什麼? – user717452
「MM/dd/y」 - (後綴限制的更多字符) – Logan