从iOS相机卷获取图片的时区
我试图确定从EXIF数据读取的图片的时区(转换以UTC格式拍摄的日期)。我尝试拍摄一张照片,然后检查其元数据:从iOS相机卷获取图片的时区,ios,timezone,exif,alassetslibrary,Ios,Timezone,Exif,Alassetslibrary,我试图确定从EXIF数据读取的图片的时区(转换以UTC格式拍摄的日期)。我尝试拍摄一张照片,然后检查其元数据: { ColorModel = RGB; DPIHeight = 72; DPIWidth = 72; Depth = 8; Orientation = 6; PixelHeight = 1936; PixelWidth = 2592; "{Exif}" = { ApertureValue = "2.
{
ColorModel = RGB;
DPIHeight = 72;
DPIWidth = 72;
Depth = 8;
Orientation = 6;
PixelHeight = 1936;
PixelWidth = 2592;
"{Exif}" = {
ApertureValue = "2.970854";
BrightnessValue = "-2.571174";
ColorSpace = 1;
ComponentsConfiguration = (
1,
2,
3,
0
);
DateTimeDigitized = "2012:12:13 01:21:55";
DateTimeOriginal = "2012:12:13 01:21:55";
ExifVersion = (
2,
2,
1
);
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = "0.06666667";
FNumber = "2.8";
Flash = 16;
FlashPixVersion = (
1,
0
);
FocalLenIn35mmFilm = 35;
FocalLength = "3.85";
ISOSpeedRatings = (
1000
);
MeteringMode = 5;
PixelXDimension = 2592;
PixelYDimension = 1936;
SceneCaptureType = 0;
SensingMethod = 2;
ShutterSpeedValue = "3.9112";
SubjectArea = (
1295,
967,
699,
696
);
WhiteBalance = 0;
};
"{GPS}" = {
Altitude = "258.794";
AltitudeRef = 0;
ImgDirection = "24.38477";
ImgDirectionRef = T;
Latitude = "45.02183333333333";
LatitudeRef = N;
Longitude = "7.610833333333334";
LongitudeRef = E;
TimeStamp = "00:21:53.87";
};
"{TIFF}" = {
DateTime = "2012:12:13 01:21:55";
Make = Apple;
Model = "iPhone 4";
Orientation = 6;
ResolutionUnit = 2;
Software = "6.0.1";
XResolution = 72;
YResolution = 72;
"_YCbCrPositioning" = 1;
};
}
它似乎有本地时间(DateTimeOriginal)和UTC时间({GPS}->TimeStamp),但没有关于这两个时间之间偏移量的指示。我可以做一些事情来确定DateTimeOriginal和TimeStamp之间的差异,但是第二个没有日期,所以如果它们跨越两个不同的日期,这似乎很棘手
有没有办法获取完整的UTC日期,或者带有时区的本地时间
我也在考虑根据纬度/经度数据确定时区,但这似乎也很复杂,因为它涉及使用外部服务从坐标中获取国家。我认为最好的办法是使用web服务。。我不认为你能从中得到什么 如果您选择此选项,请查看。我听说它可能会遭受时间偏移(虽然我没有看到),但你不会在意,因为你想要的只是时区 它非常容易使用,例如,如果您想要法国巴黎的时区(坐标48°51'44'N 2°21'03E),您可以调用此页面:,并得到以下xml文件:
<timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone.xsd">
<version>1.0</version>
<location>
<latitude>40.71417</latitude>
<longitude>2.2103</longitude>
</location>
<offset>1</offset>
<suffix>A</suffix>
<localtime>13 Dec 2012 09:57:58</localtime>
<isotime>2012-12-13 09:57:58 +0100</isotime>
<utctime>2012-12-13 08:57:58</utctime>
<dst>False</dst>
</timezone>
1
40.71417
2.2103
1.
A.
2012年12月13日09:57:58
2012-12-13 09:57:58 +0100
2012-12-13 08:57:58
假的
您应该能够从时间戳中获取UTC日期,但我没有找到任何文档支持它
您可以尝试以下方法:
//ALAsset *asset is your photo
NSDate *timestamp = (NSDate *)[asset valueForProperty:@"ALAssetPropertyDate";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:timestamp];
NSLog (@"UTC timestamp: %@", dateString);
从中获取的转换非常感谢,它似乎是有意义的,而且是正确的。我选择了rdurand的答案,因为他建议我使用有趣的Web服务(即使这不是我喜欢的方式,但似乎是唯一的方式)。您的方法在技术上是正确的,但我认为,在这种情况下是不可行的,因为[asset valueForProperty:@“ALAssetPropertyDate”]不包含“起始”时区,因此如果我将其转换为UTC,它将使用手机的当前时区,而不是照片的时区(它们不必相同)。