I have the need to store both local time as per users timezone and UTC time in a transaction table using core data
What I want is as follows
createDate = "2016-12-26T03:19:38+08:00"; <--- This should reflect the users local timezone, in this case I am in China so GMT+8 is correct
createDateUtc = "2016-12-25T19:19:38+00:00"; <---- This should reflect the same timestamp but represented in UTC
I have tried various formatters but for some reason I cannot get the result I want
Here are my two formatters
NSDateFormatter *dateFormatterWithTz = [[NSDateFormatter alloc] init];
[dateFormatterWithTz setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
NSDateFormatter *dateFormatterUtc = [[NSDateFormatter alloc] init];
[dateFormatterUtc setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
//[dateFormatterUtc setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
here is how I create the date variables
NSDate *createdDateUtc = [NSDate date];
NSDate *createdDate = [NSDate dateWithTimeInterval:[[NSTimeZone systemTimeZone] secondsFromGMT] sinceDate:createdDateUtc];
Here is what the array looks like which is incorrect as you can see it created my Utc date as my local date and pushed the create date to tomorrow and still using the same time offset, I am so confused
createdDate = "2016-12-25T03:19:38+08:00";
createdDateUtc = "2016-12-24T19:19:38+08:00";