Timestamp和String相互转化

Timestamp转化为String:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义格式,不显示毫秒
Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时间
String str = df.format(now);

String转化为Timestamp:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = df.format(new Date());
Timestamp ts = Timestamp.valueOf(time);

posted @ 2022-06-09 17:09  Arborblog  阅读(8203)  评论(0)    收藏  举报