KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > datetime > converters > GregorianCalendarConverter


1 package jodd.datetime.converters;
2
3 import java.util.Calendar;
4 import java.util.GregorianCalendar;
5
6 import jodd.datetime.DateTimeStamp;
7 import jodd.datetime.JDateTime;
8
9 public class GregorianCalendarConverter implements jodd.datetime.JdtConverter {
10
11     public void load(JDateTime gt, Object o) {
12         if (o instanceof GregorianCalendar) {
13             GregorianCalendar c = (GregorianCalendar) o;
14             gt.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND) + (double) c.get(Calendar.MILLISECOND) / 1000);
15         }
16     }
17
18     public Object get(JDateTime gt) {
19         GregorianCalendar c = new GregorianCalendar();
20         store(gt, c);
21         return c;
22     }
23
24
25     public void store(JDateTime gt, Object o) {
26         if (o instanceof GregorianCalendar) {
27             GregorianCalendar gc = (GregorianCalendar) o;
28             DateTimeStamp time = gt.getDateTimeStamp();
29             gc.set(time.year, time.month - 1, time.day, time.hour, time.minute, (int)time.second);
30             gc.set(GregorianCalendar.MILLISECOND, (int) ((time.second - (int)time.second) * 1000));
31         }
32     }
33 }
34
Popular Tags