Date Format - time zone

无人久伴 提交于 2020-02-24 20:55:31

问题


I receive from the server a string with a date that looks like this: "2013-03-29T15:27:00Z". How can I format it and transform it into an NSDate?


回答1:


Try this:

[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"];



回答2:


    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);



回答3:


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];


来源:https://stackoverflow.com/questions/15922971/date-format-time-zone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!