2013-03-14 51 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