android中的图像/图片/ jpg的日期问题(DATE_TAKEN) [英] date problem (DATE_TAKEN) for images/pictures/jpg in android
问题描述
我已经在Stackoverflow链接中通过以下已回答的问题。
,其代码如下所示。
I have gonethrough the following answered question in Stackoverflow link. which has this codes as shown below.
这里我对图像的DATE_TAKEN部分感兴趣。我已经尝试过这个代码,除了日期之外它还能完美运行。它在logcat中给出了一些数字...例如:'date_taken是2007年11月26日的图像,显示Log.i的日期是 1196066358000 。有没有办法将其解析回实际日期格式。
Here I'm interested on the DATE_TAKEN part of the image. I have tried this code and it is working perfectly except for the date. It is giving out some numbers in the logcat... For eg: An image whose' date_taken is 26th November 2007, the date shown Log.i is "1196066358000". Is there any way to parse this back to a real date format.
String[] projection = new String[]{
MediaStore.Images.Media._ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DATE_TAKEN
};
// Get the base URI for the People table in the Contacts content provider.
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
// Make the query.
Cursor cur = managedQuery(images,
projection, // Which columns to return
"", // Which rows to return (all rows)
null, // Selection arguments (none)
"" // Ordering
);
Log.i("ListingImages"," query count="+cur.getCount());
if (cur.moveToFirst()) {
String bucket;
String date;
int bucketColumn = cur.getColumnIndex(
MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
int dateColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATE_TAKEN);
do {
// Get the field values
bucket = cur.getString(bucketColumn);
date = cur.getString(dateColumn);
// Do something with the values.
Log.i("ListingImages", " bucket=" + bucket
+ " date_taken=" + date);
推荐答案
Abat,
自从纪元以来,您所获得的价值可能是UTC毫秒。要将其转换为可读格式,请尝试以下操作:
Perhaps that value you are getting is in UTC millis since the epoch. To convert that to a readable format try the following:
Calendar myCal;
myCal.setTimeInMillis(milliVal);
Date dateText = new Date(myCal.get(Calendar.YEAR)-1900,
myCal.get(Calendar.MONTH),
myCal.get(Calendar.DAY_OF_MONTH),
myCal.get(Calendar.HOUR_OF_DAY),
myCal.get(Calendar.MINUTE));
Log.d("MyApp", "DATE: " + android.text.format.DateFormat.format("MM/dd/yyyy hh:mm", dateText));
这篇关于android中的图像/图片/ jpg的日期问题(DATE_TAKEN)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!