關於JAVA中DateFormat的問題
數據庫:mysql
表: data_store_table
字段:DateTime
字段類型:TIMESTAMP
默認值:CURRENT_TIMESTAMP
String sql= "select max(`DateTime`),min(`DateTime`) from data_store_table where Work_Order= "+Work_Order;
ResultSet rs=condb.executeQuery(sql);
if(rs!=null&&rs.next()){
java.util.Date max=rs.getTimestamp(1);
java.util.Date min=rs.getTimestamp(2);
System.out.println(max);
System.out.println(min); DateFormat df=new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss ");
String from=df.format(min);
String to=df.format(max);
System.out.println(to);
System.out.println(from);
}
DateFormat 發生錯誤
max:2007-03-20 14:09:39.0
min:2007-03-19 09:54:11.0
to:2007-03-20 02:09:39
from:2007-03-19 09:54:11
------解决方案--------------------将hh:mm:ss换成HH:mm:ss就解决了
hh代表12小时制,HH代表24小时制
System.out.println(min);DateFormat df=new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss ");