可能您正在查看String
表示,Timestamp
对象通过使用System.out.println
或其他方法在控制台中打印数据库引擎或其Java表示,请注意,实际存储的数据(在Java方面或在您的数据库引擎中)是一个代表自纪元以来的时间(通常为1970年1月1日)以及您想要/需要存储的日期的数字。
您不应讲究String
格式是当你消耗您Timestamp
表示。这可以如果你申请同一SimpleDateFormat
让你timestamp
对象的String
表示很容易地以实例阐述:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentTime = df.format(new Date());
Timestamp timestamp = Timestamp.valueOf(currentTime)
//will print without showing the .x part
String currentTimeFromTimestamp = df.format(currentTime);
无论如何,如果你想在当前时间,就直接从new Date
结果创建Timestamp
:
Timestamp timestamp = new Timestamp(new Date().getTime());
你能详细点吗?谢谢 – TonyGW