I have a question about how timezone in [NSDate date] works. In my app, I am making a PUT web service call in which I have to send in the date in UTC, converted to milliseconds.
-(NSNumber *) dateToMillis: (NSDate *) date
{
long long val = (long long)[date timeIntervalSince1970] *1000.0;
return @(val);
}
NSDate *date = [NSDate date];
NSLog(@"Date - %@", [self dateToMillis:date]);
NSTimeInterval timeZoneSeconds = [[NSTimeZone timeZoneWithName:@"CST"] secondsFromGMT];
NSDate *dateInUTC = [date dateByAddingTimeInterval:timeZoneSeconds];
NSLog(@"Date UTC - %@", [self dateToMillis:dateInUTC]);
I assumed [NSDate date] would be in local timezone (CST) and tried to convert it to UTC, but both NSlogs print exactly the same value.
Does [NSDate date] not return the date time in local timezone?