我写了这段代码来将字符串转换为时间戳:
String timeStamp = "2012-04-13 09:00:30";
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date parsedDate = sdf.parse(timeStamp);
System.out.println(parsedDate.toString());
java.sql.Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime());
System.out.println(timestamp.toString());
}catch (Exception e) {
// TODO: handle exception
}
我得到的输出是:
2012-04-13 09:00:30.0
但我希望输出为:
2012-04-13 09:00:30
即我最后不需要 .0
请建议
谢谢,