View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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