《Timestamp与Date互转.docx》由会员分享,可在线阅读,更多相关《Timestamp与Date互转.docx(1页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、先贴上我的实体类,import java. util. Date;public class Order private int id;private int door_id;private String order_no;private String order_type;private int pnum;private String cashier;private Date order_time;private Date paytime;private String pay_type;private double price;正题来了:Timestamp转Date (数据库数据封装到实体类)
2、rs 是 ResultSet 类型Timestamp ts = rs. getTimestamp(7);Date date二new Date();date=ts;order. setOrder time(date);Date 转 Timestamp:S i mp1eDat eFormat sdf=new SimpleDateFormat(yyyy-MM-ddString order_time=sdf. format(order. getOrder_time();添加至数据库:psmt. setTimestamp(6, java. sql. Timestamp. ra7e0f(order_time)