I retrieve following values from the media store
MediaStore.Images.Media.DATE_TAKEN
MediaStore.Images.Media.DATE_MODIFIED
And read the dates from the result like following:
int dateTakenColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN);
int dateModifiedColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED);
String dateToken = cursor.getString(dateTakenColumn);
String dateModified = cursor.getString(dateModifiedColumn);
long lDateToken = dateToken != null ? Long.parseLong(dateToken) : 0;
long lDateModified = dateModified != null ? Long.parseLong(dateModified) : 0;
And can see following behaviour (example values):
lDateToken
looks like following: 1450696995000 <= CORRECTlDateModified
looks like following: 1450696995 <= WRONGIt seems like the modification dates are all cut off. I checked the real files last modified date with a file explorer, and the values should be fine, but I always get such short numbers from my media files.
Any ideas on why this happens?
PS: checked this http://developer.android.com/reference/android/provider/MediaStore.Images.ImageColumns.html, but the modified field is not listed there...
DATE_TAKEN
is in milliseconds since 1970.
See the docs
DATE_MODIFIED
is in seconds since 1970, so just multiply it by 1000 and it'll be fine.
See the docs
Just multiply it by 1000 to get correct date
fun convertLongToDate(time: Long): String =
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
DateTimeFormatter.ofPattern("dd MMMM yyyy").format(
Instant.ofEpochMilli(time*1000)
.atZone(ZoneId.systemDefault())
.toLocalDate())
} else {
SimpleDateFormat("dd MMMM yyyy").format(
Date(time * 1000)
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With