So today I am dealing with a server outside my timezone and started seeing something I think is weird....
Code:
on the phone...
- (NSString *)getUTCDateString: (NSDate *)theDate
{
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:SS.SSS'Z'"];
return [dateFormatter stringFromDate:theDate];
}
- (NSString *)getLocalDateString: (NSDate *)theDate
{
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
return [dateFormatter stringFromDate:theDate];
}
...
NSDate *now = [NSDate date];
NSString *nowLocal = [self getLocalDateString:now];
NSString *nowUTC = [self getUTCDateString:now];
So, was I wrong in the hopes that the nowLocal and & nowUTC would be off by exactly an hour, and not have RANDOM seconds from "somewhere"???
This data is going into JSON, for transmission to the server.
Output I've been getting:
nowLocal = "2015-10-06 01:08:42";
nowUTC = "2015-10-06T19:08:48.487Z";
nowLocal = "2015-10-06 01:09:48";
nowUTC = "2015-10-06T19:09:58.588Z";
nowLocal = "2015-10-06 01:10:18";
nowUTC = "2015-10-06T19:10:15.150Z";
nowLocal = "2015-10-06 01:10:22";
nowUTC = "2015-10-06T19:10:75.754Z";
nowLocal = "2015-10-06 01:10:27";
nowUTC = "2015-10-06T19:10:67.674Z";
nowLocal = "2015-10-06 01:10:35";
nowUTC = "2015-10-06T19:10:74.748Z";
Anyone know what's going on here?
I am converting to "UTC from local" in iOS and then back to local in PHP in another timezone, and I need the seconds to match.
Am I really supposed to believe that everyone just ignores the seconds are off? No, these aren't transmit seconds!