我在postgres有一个字段
Column | Type
created_at | timestamp without time zone
我在Java中将unix时间戳存储在long中
long createdAtTime = data.getcreatedAtTime();
我想将它转换为java中的时间戳,这样我就可以用activejdbc将其存储到postgres中。
我尝试了以下几种方法
Date convertedTime = new Date(createdAtTime*1000L);
record.set("created_at", convertedTime);
record.saveIt();
但我得到以下错误:
Can't infer the SQL type to use for an instance of java.util.Date. Use setObject() with an explicit Types value to specify the type to use.
我应该先使用不同的方式转换日期吗?
发布于 2014-12-18 02:27:55
java.sql.Timestamp timestamp = new Timestamp(createdAtTime*1000L);
record.set("created_at", convertedTime);
record.saveIt();
而不是util,直到您尝试使用java.sql.Date。它是一种原生类型的SQL。
发布于 2018-10-15 18:24:02
我看到您的数据库列将值存储为不带时区的时间戳,您为什么不尝试这样做
Timestamp current = Timestamp.from(Instant.now());
record.set("created_at", current);//I don't know if you might need to parse
record.saveIt();
https://stackoverflow.com/questions/27531844
复制相似问题