开发者

Convert NSString to NSDate that has +00:00 at the end of it?

开发者 https://www.devze.com 2023-03-22 17:16 出处:网络
Can someone please tell me how I can convert this string: 2011-07-25T10:12:59-05:00 to an NSDate object? 开发者_如何转开发I have converted GMT date strings before with an NSDateFormat that looked

Can someone please tell me how I can convert this string:

2011-07-25T10:12:59-05:00 

to an NSDate object? 开发者_如何转开发I have converted GMT date strings before with an NSDateFormat that looked like @"yyyy-MM-dd'T'HH:mm:ss.SSSS", but I have no idea how to configure it for this string.

Also, what do I set my [NSDateFormatter timeZone] to be?

Any help will be greatly appreciated. Thanks!


Problem Solved !

You can convert your string to NSDate this way,

NSString *dateString = @"2011-07-25T10:12:59-05:00";
NSDateFormatter *df = [NSDateFormatter new];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssz"];
NSDate *date = [df dateFromString:dateString];
NSLog(@"%@", date);
0

精彩评论

暂无评论...
验证码 换一张
取 消