NeilMortonNet
NeilMortonNet

Reputation: 1530

iOS Date format issue within App receipt

I am parsing the JSON returned from App Store when verifying a receipt.

One of the public fields is original_purchase_date. However, the date that is returned here is in the format of "2014-05-30 14:05:51 Etc/GMT". The issue being that when I try to compare this, the suffix (Etc/GMT) appears to be causing issues. I am trying to understand how to manage this, as this suffix could be any timezone (say America/Los_Angeles or whatever).

Is there a way of converting this into a useable format?

I know in the receipt there is also a field original_purchase_date_ms which is seconds since 1970 I suspect, however, this is a private field (not called out in any docs), so I don't want to rely on its use, only to find the app rejected, or Apple later remove the field!

Thanks in advance.

Upvotes: 3

Views: 568

Answers (1)

Sam B
Sam B

Reputation: 27608

Sample Code:

NSString *oldDateStr = [NSString stringWithFormat: @"2014-05-30 14:05:51 Etc/GMT"];
NSString *newDateStr = [oldDateStr stringByReplacingOccurrencesOfString:@"Etc/GMT" withString:@""];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date1 = [dateFormat dateFromString:newDateStr];

Upvotes: 2

Related Questions