db使用timestamp,纳秒信息丢失
- 没有分析,直接看解决方法
private Timestamp convertToUtc(Timestamp localTime) {
Timestamp utcTimeStamp = new Timestamp(localTime.getTime() + getLocalToUtcDelta());
// 补偿丢失的纳秒精度
utcTimeStamp.setNanos(localTime.getNanos());
return utcTimeStamp;
}
private long getLocalToUtcDelta() {
Calendar local = Calendar.getInstance();
local.clear();
local.set(1970, Calendar.JANUARY, 1, 0, 0, 0);
return local.getTimeInMillis();
}
网友评论