简体   繁体   中英

NSDateFormatter dateFromString returning always nil

I'm trying to get date from a string having this format :

dateString = @"2014-10-15T00:00:00.000Z"

I've tried many kinds of NSDateFormatter format such as : @"yyyy-MM-dd" or "yyyy-MM-ddTHH:mm:ss.SSS" but I'm having always nil into my NSDate Variable.

suggestions ?

Best regards

Please try below format @"yyyy-MM-dd'T'HH:mm:ss.SSSZ"

NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
[df setTimeZone:[NSTimeZone systemTimeZone]];
NSDate *dd = [df dateFromString:@"2014-10-15T00:00:00.000Z"];
NSLog(@"%@",dd);

and i got below output.

2014-10-15 00:00:00 +0000

Maybe this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM