public class FieldTime extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Inserts the current date and time.
Examples:
Shows how to display the current time using the TIME field.
public void fieldTime() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// By default, time is displayed in the "h:mm am/pm" format.
FieldTime field = insertFieldTime(builder, "");
Assert.assertEquals(" TIME ", field.getFieldCode());
// We can use the \@ flag to change the format of our displayed time.
field = insertFieldTime(builder, "\\@ HHmm");
Assert.assertEquals(" TIME \\@ HHmm", field.getFieldCode());
// We can adjust the format to get TIME field to also display the date, according to the Gregorian calendar.
field = insertFieldTime(builder, "\\@ \"M/d/yyyy h mm:ss am/pm\"");
Assert.assertEquals(field.getFieldCode(), " TIME \\@ \"M/d/yyyy h mm:ss am/pm\"");
doc.save(getArtifactsDir() + "Field.TIME.docx");
}
/// <summary>
/// Use a document builder to insert a TIME field, insert a new paragraph and return the field.
/// </summary>
private FieldTime insertFieldTime(final DocumentBuilder builder, final String format) throws Exception {
FieldTime field = (FieldTime) builder.insertField(FieldType.FIELD_TIME, true);
builder.moveTo(field.getSeparator());
builder.write(format);
builder.moveTo(field.getStart().getParentNode());
builder.insertParagraph();
return field;
}
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, update