KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jodd.datetime.converters;
2
3 import java.sql.Date;
4
5 import jodd.datetime.DateTimeStamp;
6 import jodd.datetime.JDateTime;
7
8 public class SqlDateConverter implements jodd.datetime.JdtConverter {
9
10     public void load(JDateTime gt, Object o) {
11         if (o instanceof Date) {
12             Date d = (Date) o;
13             gt.set(1900 + d.getYear(), d.getMonth() + 1, d.getDate());
14         }
15     }
16
17     public Object get(JDateTime gt) {
18         DateTimeStamp time = gt.getDateTimeStamp();
19         return new Date(time.year - 1900, time.month - 1, time.day);
20     }
21
22     public void store(JDateTime gt, Object o) {
23         if (o instanceof Date) {
24             Date d = (Date) o;
25             DateTimeStamp time = gt.getDateTimeStamp();
26             d.setYear(time.year - 1900);
27             d.setMonth(time.month - 1);
28             d.setDate(time.day);
29         }
30     }
31
32 }
33
Popular Tags