2015-09-16 32 views
-1

我正在嘗試構建一個圖庫應用程序。我已經從MediaStore.Images中添加了獲取的圖像路徑和日期。從Gallery返回的日期總是返回1970年1月1日

我用下面的代碼:

​​

請參閱我已經發布below.The圖像路徑即將完美的logcat的,所以在milliseconds.But的時候,我試圖在毫秒轉換成日期格式,然後我總是得到:1970年1月17日

09-16 11:10:53.994: I/System.out(10098): date in format--->January 17, 1970 8:49PM 
    09-16 11:10:53.994: I/System.out(10098): Imagepath-->/storage/emulated/0/ModFace/Modface727142626.jpg 
    09-16 11:10:53.994: I/System.out(10098): date--->1437988950 
    09-16 11:10:53.994: I/System.out(10098): date in format--->January 17, 1970 8:56PM 
    09-16 11:10:53.994: I/System.out(10098): Imagepath-->/storage/emulated/0/ModFace/Modface727142639.jpg 
    09-16 11:10:53.994: I/System.out(10098): date--->1437988950 
    09-16 11:10:53.994: I/System.out(10098): date in format--->January 17, 1970 8:56PM 
    09-16 11:10:53.994: I/System.out(10098): Imagepath-->/storage/emulated/0/data/data/images/SILogo2015.png 
    09-16 11:10:53.994: I/System.out(10098): date--->1438252547 
    09-16 11:10:53.994: I/System.out(10098): date in format--->January 17, 1970 9:00PM 
    09-16 11:10:53.994: I/System.out(10098): Imagepath-->/storage/emulated/0/Download/ebook.png 
    09-16 11:10:53.994: I/System.out(10098): date--->1438668694 
    09-16 11:10:53.994: I/System.out(10098): date in format--->January 17, 1970 9:07PM 
    09-16 11:10:53.994: I/System.out(10098): Imagepath-->/storage/emulated/0/DCIM/Camera/20150811_153514.jpg 
    09-16 11:10:53.994: I/System.out(10098): date--->1439287514 
    09-16 11:10:53.994: I/System.out(10098): date in format--->January 17, 1970 9:18PM 
    09-16 11:10:53.994: I/System.out(10098): Imagepath-->/storage/emulated/0/Pictures/mainstreamtemp.jpg 
    09-16 11:10:53.994: I/System.out(10098): date--->1439800096 
    09-16 11:10:53.994: I/System.out(10098): date in format--->January 17, 1970 9:26PM 
    09-16 11:10:53.994: I/System.out(10098): Imagepath-->/storage/emulated/0/Pictures/mainstream2.jpg 
    09-16 11:10:53.994: I/System.out(10098): date--->1439800096 
    09-16 11:10:53.994: I/System.out(10098): date in format--->January 17, 1970 9:26PM 
    09-16 11:10:54.024: I/System.out(10098): date in format--->January 17, 1970 10:01PM 
    09-16 11:10:54.024: I/System.out(10098): Imagepath-->/storage/emulated/0/shiatoolkitimages/mashlool07.gif 
    09-16 11:10:54.024: I/System.out(10098): date--->1441888058 
    09-16 11:10:54.024: I/System.out(10098): date in format--->January 17, 1970 10:01PM 
    09-16 11:10:54.024: I/System.out(10098): Imagepath-->/storage/emulated/0/shiatoolkitimages/mashlool08.gif 
    09-16 11:10:54.024: I/System.out(10098): date--->1441888058 
    09-16 11:10:54.024: I/System.out(10098): date in format--->January 17, 1970 10:01PM 
    09-16 11:10:54.024: I/System.out(10098): Imagepath-->/storage/emulated/0/shiatoolkitimages/mashlool09.gif 
    09-16 11:10:54.024: I/System.out(10098): date--->1441888058 
    09-16 11:10:54.024: I/System.out(10098): Imagepath-->/storage/emulated/0/shiatoolkitimages/mashlool10.gif 
    09-16 11:10:54.024: I/System.out(10098): date--->1441888058 
    09-16 11:10:54.024: I/System.out(10098): Imagepath-->/storage/emulated/0/shiatoolkitimages/mashlool11.gif 
    09-16 11:10:54.024: I/System.out(10098): date in format--->January 17, 1970 10:01PM 
    09-16 11:10:54.024: I/System.out(10098): Imagepath-->/storage/emulated/0/siat_hadith.png 
    09-16 11:10:54.024: I/System.out(10098): date--->1442042302 
    09-16 11:10:54.024: I/System.out(10098): date in format--->January 17, 1970 10:04PM 

我也曾嘗試另一種方法來轉換日期米利斯,但最終得到相同的結果:

public static String convertDate(long dateInMilliseconds,String dateFormat) { 
     return DateFormat.format(dateFormat, dateInMilliseconds).toString(); 
    } 

回答

4

你是從你的光標獲得的數量是在Unix Time,其對自1月經過1970年對於要在毫秒值的生成日期秒數的格式。簡單的解決方案是將你的結果乘以1000,你很好。

+1

或使用'TimeUnit' –

+0

謝謝您reply.I會嘗試。 – kgandroid

+0

它的工作。謝謝。 – kgandroid

2

取而代之的是

  Date d = new Date(dateofimage); 
     java.text.DateFormat formatter = new SimpleDateFormat("MMMM dd, yyyy h:mmaa"); 
     String dateString = formatter.format(d); 

試試這個

 Timestamp timeStamp = new Timestamp(dateofimage * 1000); 
     String dateString = timeStamp.toLocaleString(); 
+0

感謝您的答覆。我會試試這個。 – kgandroid

+0

如果有幫助,請提出答案。它可能也會幫助其他人.. –

+0

toLocaleString();被取消 – kgandroid

相關問題