我写这段代码转换串时间戳:时间戳格式匹配
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
ie ie not need the0.0 the end
请建议
感谢,
为什么不只是从一个转换到另一个呢?这不仅仅对你有帮助吗?您可以将时间戳转换为日期,或者其他方式... java.sql.Timestamp sqlTimeStamp = new java.sql.Timestamp(date.getTime()); 如果这还不够,请您详细说明一下吗? – 2012-04-15 09:12:39