Search code examples
iosnsdatenstimezonephotosframework

What Time Zone is used by PHAsset creationDate?


PHAsset creationDate returns an NSDate that is constructed as if all of the photos were taken in the same "home" Time Zone. E.g., on a given iPhone, a photo taken at 4PM in New York will have the same creationDate as one taken at 4PM in California. This is convenient: as long as you display the date in the "home" Time Zone, it will show the local time where the photo was captured, which is usually what you want to see. If PHAsset returned a UTC creationDate, then you would need to know what Time Zone it was captured in, which may not even be known by the iPhone, whereas the local capture time, which user wants to see anyway, is likely to be available with any photo. So, Photos framework just reverse encodes that local time to an NSDate, using some fixed Time Zone.

Does anyone know how to determine what Time Zone the Photos framework is using for this? Changing the iPhone settings ([NSTimeZone systemTimeZone]) does not seem to effect it, even after system reboot. Is there a more stable system Time Zone? Or, is this something the Photos framework is saving?

I know one way I can determine it, which is to read the photo meta data to get the local time when the photo was captured. Then compare that to the PHAsset creationDate to see what offset was used. But, that is pretty ugly if there is a legitimate way to query this parameter. Or, more importantly, to know under what conditions it may change.

Here is an example of a photo taken in Australia (GMT+10) being opened on a California (GMT-7) based iPhone: PHAsset creationDate: 2015-03-09 22:57:35 +0000 Actual UTC capture date: 2015:03:09 05:57:34 +0000 Australian capture date: 2015:03:09 15:57:35 (GMT+10)

Notice the PHAsset creationDate does not match the actual creation date. Rather it is the UTC time that corresponds to 15:57:35 in California time zone. Here is subset of metadata from the photo

{ "{Exif}" = { DateTimeDigitized = "2015:03:09 15:57:35"; }; "{GPS}" = { DateStamp = "2015:03:09"; TimeStamp = "05:57:34"; }; "{TIFF}" = { DateTime = "2015:03:09 15:57:35"; }; }


Solution

  • There is no constant "home" timeZone, as I had guessed from examining PHAsset behavior on my phone. When a photo is first saved, a UTC creationDate will be imputed based on the iPhone's current time zone, and the local time the photo was created (from jpeg metadata if not captured by the iPhone camera). So, there is no constant "home" timeZone, but a different one depending on when the photo was saved. As long as the photo was captured in the same timeZone where it is first saved to the iPhone, then the creationDate will be correct.

    The behavior I was seeing only occurred because all of my photos taken in a different time zone were captured on an older iPhone and carried forward to this one. The constant "home" time zone I saw was simply the time zone that was current when that transfer occurred. This had nice side effect of displaying local time correctly, so I had assumed it was by design for all photos captured in different time zones.