我正在尝试确定从其EXIF数据中读取的图片的时区(以转换以UTC格式拍摄的日期)。我试图拍照,然后检查它的元数据:
{
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),但没有迹象表明这两者之间的偏移量。我可以做一些事情来确定日期时间原始和时间戳之间的差异,但是第二个没有日期,所以在它们跨越两个不同日期的情况下似乎很棘手。
有没有办法获得完整的UTC日期,或当地时间与时区?
我也在考虑从纬度/纬度数据中确定时区,但这似乎也很复杂,因为它涉及使用外部服务从坐标获取国家/地区。
我认为你最好的选择是使用网络服务。我认为你无法从中得到任何东西。
如果选择此选项,请查看地球工具。我听说它可能遭受时间偏移(虽然我没有看到),但你不会在乎,因为你想要的只是时区。
它真的很容易使用,例如,如果你想要法国巴黎的时区(坐标48°51'44'N 2°21'03E),你调用这个页面:http://www.earthtools.org/timezone-1.1/40.71417/2.2103,你会得到这个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>
您应该能够从时间戳中获取 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);
从 https://stackoverflow.com/a/2615847/653513 转换