Meep Meep - 1 year ago 125
Android Question

Get the added/modified/taken date of the video from MediaStore

Where do I get the taken date of the video from MediaStore? I got the following fields from MediaStore.


Those fields returned seemly default values -

dateModified: 1477043336
dateTaken: 1477043336000
dateAdded: 1477043352

Formatted dates -

dateModified: 01/01/1970
dateTaken: 01/01/1970
dateAdded: 01/01/1970

I double checked the stock gallery > random video file and I do see the correct dates. I looked at the video columns in MediaStore and I didn't see any other columns which has correct dates.

SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
String formattedDate = dateFormat.format(new Date(row.getColumnIndex(MediaStore.Video.Media.DATE_MODIFIED)));

String dateModified = dateFormat.format(new Date(row.getColumnIndex(MediaStore.Video.Media.DATE_MODIFIED)));
String dateTaken = dateFormat.format(new Date(row.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN) * 1000L));
String dateAdded = dateFormat.format(new Date(row.getColumnIndex(MediaStore.Video.Media.DATE_ADDED) * 1000L));

Log.d(TAG, "dateModified: "+dateModified);
Log.d(TAG, "dateTaken: "+dateTaken);
Log.d(TAG, "dateAdded: "+dateAdded);

Log.d(TAG, "dateModified: "+row.getString(row.getColumnIndex(MediaStore.Video.Media.DATE_MODIFIED)));
Log.d(TAG, "dateTaken: "+row.getString(row.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN)));
Log.d(TAG, "dateAdded: "+row.getString(row.getColumnIndex(MediaStore.Video.Media.DATE_ADDED)));

Answer Source

Those fields returned seemly default values

I do not know why your second one has three extra zeros at the end. But, using a Unix date converter site:

  • dateModified = 1477043336 = Fri, 21 Oct 2016 09:48:56 GMT
  • dateAdded = 1477043352 = Fri, 21 Oct 2016 09:49:12 GMT

And your dateTaken, without the zeros, is the same as dateModified. So, assuming you can figure out where your zeros came from (such as by randomly deciding to multiply the value by 1000L), you have valid timestamps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download