1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.date;
17
18 import static java.util.TimeZone.getTimeZone;
19
20 import java.text.SimpleDateFormat;
21 import java.util.Date;
22
23 import org.junit.Test;
24
25 public class DateTest {
26
27 @Test
28 public void test() {
29 try {
30 long second = 1000;
31 long minute = 60 * second;
32 long hour = 60 * minute;
33 long day = 24 * hour;
34 long year = 365 * day;
35 SimpleDateFormat formatter = getFormatter();
36 System.out.println(formatter.format(new Date(Long.MIN_VALUE)));
37 System.out.println(formatter.format(new Date(Long.MAX_VALUE)));
38 String zero = "0000-01-01 00:00:00";
39 Date date1 = getParser().parse(zero);
40 Date date2 = new Date(date1.getTime() - year);
41 System.out.println(formatter.format(date1) + " " + date1.getTime());
42 System.out.println(formatter.format(date2) + " " + date2.getTime());
43 } catch (Throwable e) {
44 e.printStackTrace();
45 }
46 }
47
48 protected SimpleDateFormat getFormatter() {
49 String format = "yyyy-MM-dd HH:mm:ss.SSS z G";
50 SimpleDateFormat sdf = new SimpleDateFormat(format);
51 sdf.setTimeZone(getTimeZone("UTC"));
52 return sdf;
53 }
54
55 protected SimpleDateFormat getParser() {
56 String format = "yyyy-MM-dd HH:mm:ss";
57 SimpleDateFormat sdf = new SimpleDateFormat(format);
58 sdf.setTimeZone(getTimeZone("UTC"));
59 return sdf;
60 }
61
62 }
63