KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jodd.datetime.converters;
2
3 import java.sql.Timestamp;
4
5 import jodd.datetime.DateTimeStamp;
6 import jodd.datetime.JDateTime;
7
8 public class SqlTimestampConverter implements jodd.datetime.JdtConverter {
9
10     public void load(JDateTime gt, Object o) {
11         if (o instanceof Timestamp) {
12             Timestamp t = (Timestamp) o;
13             gt.set(1900 + t.getYear(), t.getMonth() + 1, t.getDate(), t.getHours(), t.getMinutes(), (double)t.getSeconds() + t.getNanos() / 1000000000.0d);
14         }
15     }
16
17     public Object get(JDateTime gt) {
18         DateTimeStamp time = gt.getDateTimeStamp();
19         return new Timestamp(time.year - 1900, time.month - 1, time.day, time.hour, time.minute, (int)time.second, ((int)((time.second - (int)time.second) * 1000000000)));
20     }
21
22
23     public void store(JDateTime gt, Object o) {
24         if (o instanceof Timestamp) {
25             Timestamp ts = (Timestamp) o;
26             DateTimeStamp time = gt.getDateTimeStamp();
27             ts.setYear(time.year - 1900);
28             ts.setMonth(time.month - 1);
29             ts.setDate(time.day);
30             ts.setHours(time.hour);
31             ts.setMinutes(time.minute);
32             ts.setSeconds((int)time.second);
33             ts.setNanos(((int)((time.second - (int)time.second) * 1000000000)));
34         }
35     }
36 }
37
Popular Tags