2013-04-10 134 views

回答

5

試試這個:

[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; 
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; 
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; 
NSDate *date = [formatter dateFromString:@"2013-03-29T15:27:00Z"]; 
1
NSString *departTimeDate = @"2013-03-29T15:27:00Z"; 

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; 
    NSDate *date = [dateFormatter dateFromString:departTimeDate]; 

    NSLog(@"Expected Result___ %@",date); 
+0

嗨巴爾加維,DATEFORMAT不需要''-'' :) – 2013-04-10 10:38:08

1
NSString *[email protected]"2013-03-29T15:27:00Z"; 
NSDateFormatter *dateFormatter=[NSDateFormatter new]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"]; 
NSDate *date=[dateFormatter dateFromString:string];