Java|JAVA中如何将以Date型的数据保存到数据库以Datetime型的字段中

2021/09/09 Java 共 265 字,约 1 分钟

用Timestamp就行了

recordOuttime是Date类型

import java.sql.Timestamp;
Record record = recordMapper.selectByPrimaryKey(recordId);
Date recordIntime = record.getRecordIntime();
Date dNow = new Date();
Timestamp recordOuttime = new Timestamp(dNow.getTime());
record.setRecordOuttime(recordOuttime);

文档信息

Search

    Table of Contents