try {
TextDocument doc = TextDocument.newTextDocument();
DateField dateField = Fields.createDateField(doc.newParagraph("Date:"));
Assert.assertNotNull(dateField);
TextDateElement dateEle = dateField.getOdfElement();
String oldContent = dateEle.getTextContent();
SimpleDateFormat oldFormat = new SimpleDateFormat("yyyy-MM-dd");
Date oldDate = oldFormat.parse(oldContent);
String format = "yy-MM-dd";
dateField.formatDate(format);
String newContent = dateEle.getTextContent();
SimpleDateFormat newFormat = new SimpleDateFormat(format);
Date newDate = newFormat.parse(newContent);
Assert.assertEquals(oldDate.getTime(), newDate.getTime());
} catch (Exception e) {
Logger.getLogger(FieldsTest.class.getName()).log(Level.SEVERE, null, e);