blob: 264f8c22564522484952dc8670a3d9d0fa17728c (
plain) (
blame)
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
38
|
package com.juick.xml.adapters;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
* Created by vitalyster on 15.11.2016.
*/
public class SimpleDateAdapter extends XmlAdapter<String, Date> {
private final SimpleDateFormat dateFormat;
public SimpleDateAdapter() {
dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
@Override
public String marshal(Date v) throws Exception {
if (v == null) {
return "";
}
synchronized (dateFormat) {
return dateFormat.format(v);
}
}
@Override
public Date unmarshal(String v) throws Exception {
synchronized (dateFormat) {
return dateFormat.parse(v);
}
}
}
|