KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jodd.datetime.converters;
2
3 import java.util.Calendar;
4
5 import jodd.datetime.DateTimeStamp;
6 import jodd.datetime.JDateTime;
7
8 public class CalendarConverter implements jodd.datetime.JdtConverter {
9
10     public void load(JDateTime gt, Object o) {
11         if (o instanceof Calendar) {
12             Calendar c = (Calendar) o;
13             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);
14         }
15     }
16
17     public Object get(JDateTime gt) {
18         Calendar c = Calendar.getInstance();
19         store(gt, c);
20         return c;
21     }
22
23     public void store(JDateTime gt, Object o) {
24         if (o instanceof Calendar) {
25             Calendar c = (Calendar) o;
26             DateTimeStamp time = gt.getDateTimeStamp();
27             c.set(time.year, time.month - 1, time.day, time.hour, time.minute, (int)time.second);
28             c.set(Calendar.MILLISECOND, (int) ((time.second - (int)time.second) * 1000));
29         }
30     }
31
32 }
33
Popular Tags