2013-03-14 17 views
0

我寫這收集所有的元信息(GPS:緯度,經度和日期)Java程序從圖像(使用庫的元數據,提取-2.6.4),我越來越喜歡約會「日期如何從GPSDirectory獲取日期?

GpsDirectory gpsDir = (GpsDirectory) metadata.getDirectory(GpsDirectory.class); 
GpsDescriptor gpsDesc = new GpsDescriptor(gpsDir); 
System.out.println("Date : " + gpsDesc.getGpsTimeStampDescription()); 

:UTC時間15:45:26「。是否有任何方法可以在標準格式中給出日期,如yyyy.MM.dd G'at'HH:mm:ss z?

我試圖用

gpsDir.getDate(GpsDirectory.TAG_GPS_DATE_STAMP), but it returns null 
+0

你能提供一個鏈接到元數據提取器庫的Javadoc嗎? – hd1 2013-03-14 18:21:58

回答

1

我試圖用

gpsDir.getDate(GpsDirectory.TAG_GPS_DATE_STAMP),但它返回null

docsgetDate(),它表示:「將指定標籤的值作爲java.util.Date返回,如果該值未設置或無法轉換,則返回null。」因此,gpsDir.getDate(GpsDirectory.TAG_GPS_DATE_STAMP)回報可能空,因爲你沒有叫這行:

gpsDir.setDate(GpsDirectory.TAG_GPS_DATE_STAMP, myDate); 

有其「爲」 HH給出了類似YYYY.MM.DD G規範格式日期的任何方法:MM:SSž ?

是的,只需使用SimpleDateFormat。我沒有測試過這段代碼,但是這應該可以工作:

final String OLD_FORMAT = "..."; 
final String NEW_FORMAT = "yyyy.MM.dd G at HH:mm:ss z"; 

String oldDateString = gpsDesc.getGpsTimeStampDescription(); 
String newDateString; 

SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT); 
Date d = sdf.parse(oldDateString); 
sdf.applyPattern(NEW_FORMAT); 
newDateString = sdf.format(d); 
+0

感謝Barney,我想收集與圖像一起存儲的日期。 – 2013-03-15 02:46:14