开发者

NSDateFormatter timezone (Etc/GMT) not getting parsed for dateFromString

I am getting nil for trying to convert this 2011-07-11 13:28:59 Etc/GMT into a NSDate b开发者_开发技巧y the following code

NSString *dateString=@"2011-07-11 13:28:59 Etc/GMT";
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"yyyy-MM-dd hh:mm:ss z"];
NSDate *purchaseDate = [dateformatter dateFromString:dateString];

This date is coming from apple server itself for in-app purchase validation. I've gone about lot of threads with timezone. but none of them show how to convert this Etc/GMT

i have tried z zz zzz zzzz Z ZZ ZZZ ZZZZ

what might be the issue here.


The correct dateFormat is yyyy-MM-dd HH:mm:ss VV which is what you should use to solve your problem.


// Swift Version

    let DateString = "2016-01-21 00:29:09 Etc/GMT"
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss VV"
    var dateObject = dateFormatter.date(from: DateString)


NSString *dateString=@"2011-07-11 13:28:59 Etc/GMT";
dateString = [dateString stringByReplacingOccurrencesOfString:@"Etc/GMT" withString:@"GMT"];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"yyyy-MM-dd HH:mm:ss z"];

// Or stuff....>>

NSDate *date = [dateformatter dateFromString: dateString];
NSLog(@"You may Need This  =========%@",date);
dateformatter = [[[NSDateFormatter alloc] init] autorelease];
[dateformatter setDateFormat:@"yyyy-MM-dd hh:mm:ss a"];

NSString *convertedString = [dateformatter stringFromDate:date];
NSLog(@"Converted String : %@",convertedString);

/// may help =====>> http://unicode.org/reports/tr35/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜