forked from thombergs/docx-stamper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateResolver.java
37 lines (29 loc) · 947 Bytes
/
DateResolver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package org.wickedsource.docxstamper.replace.typeresolver;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* This ITypeResolver creates a formatted date String for expressions that return a Date object.
*/
public class DateResolver extends AbstractToTextResolver<Date> {
private String formatString;
private DateFormat dateFormat;
/**
* Creates a new DateResolver.
*
* @param formatString the format to use for date formatting. See java.text.SimpleDateFormat.
*/
public DateResolver(String formatString) {
this.formatString = formatString;
this.dateFormat = new SimpleDateFormat(formatString);
}
@Override
protected String resolveStringForObject(Date date) {
synchronized (dateFormat) {
return dateFormat.format(date);
}
}
public String getFormatString() {
return formatString;
}
}