1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.commsen.jwebthumb.simplexml;
21
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
24
25 import org.simpleframework.xml.transform.Transform;
26
27 /***
28 * Implementation of {@link Transform} which transforms dates according to
29 * <code>yyyy-MM-dd HH:mm:ss</code> format.
30 *
31 * @author <a href="mailto:MilenDyankov@gmail.com">Milen Dyankov</a>
32 * @since 0.3
33 */
34 public class DateTransformer implements Transform<Date> {
35
36 public final SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
37
38
39 /***
40 * @see org.simpleframework.xml.transform.Transform#read(java.lang.String)
41 */
42 public Date read(String value) throws Exception {
43 return timeFormat.parse(value);
44 }
45
46
47 /***
48 * @see org.simpleframework.xml.transform.Transform#write(java.lang.Object)
49 */
50 public String write(Date value) throws Exception {
51 return timeFormat.format(value);
52 }
53
54 }