Iam獲取NSString格式的日期「2016-03-16T00:00:00.000 + 05:30」Iam使用以下方法將NSString日期轉換爲合適的NSDate格式,並返回null。返回null的NSString格式的日期iOS?
NSString *dateString = @"2016-03-16T00:00:00.000+05:30";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'hh:mm:ssZZZ"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:dateString];
//dateFromString returns null.
請幫助
我有這個代碼
NSString *strDateFor = [polygon valueForKey:@"effective_from"];
NSDateFormatter *dateformate=[[NSDateFormatter alloc]init];
[dateformate setDateFormat:@"yyyy-MM-dd 'T' HH:mm:ss ZZZZ"];
NSDate *date = [dateformate dateFromString:strDateFor];
NSLog(@"date : %@",date); //null
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"dd-MM-yyyy"];
NSString *strDate = [dateFormat stringFromDate:date];
NSLog(@"The strDate is - %@", strDate); //null
再次空
我應該如何糾正這種??? – Bangalore
比較字符串和格式。他們不匹配。 – gnasher729