Timestamp and interconversion Java String

Timestamp into a String:
SimpleDateFormat df = new SimpleDateFormat ( "yyyy-MM-dd HH: mm: ss"); // definition format is not displayed ms
Timestamp now = new Timestamp (System.currentTimeMillis ()); // get the current time
String str = df.format(now);
 
String into a Timestamp:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = df.format(new Date());
Timestamp ts = Timestamp.valueOf(time);

Reproduced in: https: //www.cnblogs.com/ericsun/archive/2012/06/21/2558086.html

Guess you like

Origin blog.csdn.net/weixin_33744141/article/details/93154899