2

我从服务器收到一个字符串,其日期如下所示:“2013-03-29T15:27:00Z”。如何格式化并将其转换为 NSDate?

4

3 回答 3

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"];
于 2013-04-10T10:18:13.570 回答
1
NSString *string=@"2013-03-29T15:27:00Z";
NSDateFormatter *dateFormatter=[NSDateFormatter new];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
NSDate *date=[dateFormatter dateFromString:string];
于 2013-04-10T10:19:53.597 回答
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);
于 2013-04-10T10:18:47.807 回答