How to convert date time found in EXIF meta to XSD standard?
I'm parsing some EXIF files.
One of the meta fields is Date/Time Original
in the format:
2009:09:02 03:28:43
.
My application is creating some meta-object types that wil开发者_运维技巧l be validated against a schema. My schema defines the Date/Time Original
field as being of type DateTime
.
How can I convert the above to the XSD DateTime using Java?
Use a SimpleDateFormat instance to parse the date you get from the file to a java.util.Date object, then you can use another SimpleDateFormat to convert to the XSD date format. It should look like this:
SimpleDateFormat dateParser = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
SimpleDateFormat dateConverter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date d = dateParser.parse(myExifDateString);
String xsdDateString = dateConverter.format(d);
精彩评论