android - 如何检测 Android 设备是以秒还是毫秒为单位存储媒体日期?

标签 android timestamp android-contentresolver

我有一个小问题,不同的 Android 设备返回以秒或毫秒为单位的图像拍摄日期时间戳。我使用 Intent.ACTION_PICK 然后使用内容解析器来查询结果。

我发现 MediaStore.Images.ImageColumns.DATE_TAKEN 列在 Samsung Galaxy J7 上以秒为单位返回,但在 Samsung Edge 7 上以毫秒为单位返回。如何确定设备使用的是哪一个?

最佳答案

当您处理由 Android 设备拍摄的照片时,我们可以假设不会有 2000 年之前的日期。

2000-01-01T00:00Z 的时间戳是 946684800 秒(或 946684800000 毫秒)。因此,如果该值低于 946684800000,那么您可以假设它以秒为单位。

当然你可以更精确,而不是 2000 年,你可以使用 first Android version release 之后的日期,甚至丢弃旧版本并考虑最后 N 个版本(N 可以任意设置)。以下是 Android 版本发布日期的时间戳(所有日期均基于 this link - 时间设置为午夜,偏移量为 UTC):

2008-09-23T00:00Z: 1222128000000 milliseconds
2009-02-09T00:00Z: 1234137600000 milliseconds
2009-04-27T00:00Z: 1240790400000 milliseconds
2009-09-15T00:00Z: 1252972800000 milliseconds
2009-10-26T00:00Z: 1256515200000 milliseconds
2010-05-20T00:00Z: 1274313600000 milliseconds
2010-12-06T00:00Z: 1291593600000 milliseconds
2011-02-22T00:00Z: 1298332800000 milliseconds
2011-10-18T00:00Z: 1318896000000 milliseconds
2012-07-09T00:00Z: 1341792000000 milliseconds
2013-10-31T00:00Z: 1383177600000 milliseconds
2014-11-12T00:00Z: 1415750400000 milliseconds
2015-10-23T00:00Z: 1445558400000 milliseconds
2016-08-22T00:00Z: 1471824000000 milliseconds

关于android - 如何检测 Android 设备是以秒还是毫秒为单位存储媒体日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44842300/

相关文章:

php - Date.UTC() 与 strtotime() ??为什么不同?

Mysql 时间记录为 Unixtime 而不是 Mysql Timestamp

android - 如何在 SyncAdapter 完成时通知调用 Activity?

android - 为什么 ContentResolver 看不到其他应用添加的文件?

android - onConfigurationChanged 从不触发

android - Google Analytics V4 离线事件跟踪

php - 当 mysql 时间戳 > 20 分钟时删除的时间戳比较

java - 字符串编码 - Shift_JIS/UTF-8

android - 从 ListView 中单击的 Firebase 元素中检索信息

android - 无法解析内容 ://com. android.alarmclock/alarm 的提供商