forked from alibaba/fastjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTest.java
More file actions
42 lines (29 loc) · 1.09 KB
/
Copy pathDateTest.java
File metadata and controls
42 lines (29 loc) · 1.09 KB
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
39
40
41
42
package com.alibaba.json.bvt;
import java.util.Date;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
public class DateTest extends TestCase {
public void test_date() throws Exception {
long millis = 1324138987429L;
Date date = new Date(millis);
VO vo = new VO();
vo.setDate(date);
System.out.println(JSON.toJSONString(date));
System.out.println(JSON.toJSONString(date, SerializerFeature.WriteDateUseDateFormat));
System.out.println(JSON.toJSONString(date));
System.out.println(JSON.toJSONStringWithDateFormat(vo, "yyyy-MM-dd HH:mm:ss.SSS",
SerializerFeature.PrettyFormat));
}
public static class VO {
private Date date;
@JSONField(format="yyyy-MM-dd HH:mm:ss.SS")
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
}