1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.pdf;
20
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23 import java.util.Locale;
24 import java.util.TimeZone;
25
26
27
28
29
30
31
32
33
34 public class DateBean {
35 private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC");
36
37 private static final SimpleDateFormat YEAR = new SimpleDateFormat("yyyy", Locale.US);
38 private static final SimpleDateFormat MONTH = new SimpleDateFormat("MM", Locale.US);
39 private static final SimpleDateFormat DAY = new SimpleDateFormat("dd", Locale.US);
40 private static final SimpleDateFormat HOUR = new SimpleDateFormat("HH", Locale.US);
41 private static final SimpleDateFormat MINUTE = new SimpleDateFormat("mm", Locale.US);
42 private static final SimpleDateFormat SECOND = new SimpleDateFormat("ss", Locale.US);
43 private static final SimpleDateFormat MILLI_SECOND = new SimpleDateFormat("SSS", Locale.US);
44 private static final SimpleDateFormat DATE = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
45 private static final SimpleDateFormat TIME = new SimpleDateFormat("HH:mm:ss'Z'", Locale.US);
46 private static final SimpleDateFormat DATE_TIME = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
47
48 static {
49 YEAR.setTimeZone(UTC_TIME_ZONE);
50 MONTH.setTimeZone(UTC_TIME_ZONE);
51 DAY.setTimeZone(UTC_TIME_ZONE);
52 HOUR.setTimeZone(UTC_TIME_ZONE);
53 MINUTE.setTimeZone(UTC_TIME_ZONE);
54 SECOND.setTimeZone(UTC_TIME_ZONE);
55 MILLI_SECOND.setTimeZone(UTC_TIME_ZONE);
56 DATE.setTimeZone(UTC_TIME_ZONE);
57 TIME.setTimeZone(UTC_TIME_ZONE);
58 DATE_TIME.setTimeZone(UTC_TIME_ZONE);
59 }
60
61 private Date date;
62
63
64
65
66 public DateBean() {
67 this(new Date());
68 }
69
70
71
72
73
74
75 public DateBean(final Date date) {
76 this.date = date;
77 }
78
79
80
81
82
83
84 public void setDate(final Date date) {
85 this.date = date;
86 }
87
88
89
90
91 public String getYear() {
92 synchronized (this) {
93 return YEAR.format(date);
94 }
95 }
96
97
98
99
100 public String getMonth() {
101 synchronized (this) {
102 return MONTH.format(date);
103 }
104 }
105
106
107
108
109 public String getDay() {
110 synchronized (this) {
111 return DAY.format(date);
112 }
113 }
114
115
116
117
118 public String getHour() {
119 synchronized (this) {
120 return HOUR.format(date);
121 }
122 }
123
124
125
126
127 public String getMinute() {
128 synchronized (this) {
129 return MINUTE.format(date);
130 }
131 }
132
133
134
135
136 public String getSecond() {
137 synchronized (this) {
138 return SECOND.format(date);
139 }
140 }
141
142
143
144
145 public String getMillisecond() {
146 synchronized (this) {
147 return MILLI_SECOND.format(date);
148 }
149 }
150
151
152
153
154 public String getDate() {
155 synchronized (this) {
156 return DATE.format(date);
157 }
158 }
159
160
161
162
163 public String getTime() {
164 synchronized (this) {
165 return TIME.format(date);
166 }
167 }
168
169
170
171
172 public String getDateTime() {
173 synchronized (this) {
174 return DATE_TIME.format(date);
175 }
176 }
177 }