I am getting nil for trying to convert this 2011-07-11 13:28:59 Etc/GMT
into a NSDate by 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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With