Timestame类型和String 类型的转化

Timestame类型和String 类型的转化

String转化为Timestamp:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = df.format(new Date());
Timestamp ts = Timestamp.valueOf(time);
Timestamp转化为String:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义格式
Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时间,也可以是其他需转化的时间
String str = df.format(now);

 





posted @ 2016-08-31 20:31  悟知清风  阅读(402)  评论(0编辑  收藏  举报