java.sql.Date 只能存储日期,不能存储时间
java.sql.Timestamp包含时间和日期
- Java.sql.Date,
- java.sql.Time
- java.sql.Timestamp
- 上面都java.util.Date的子类(包装类)
java.util.Date d = new java.util.Date(sqlDate.getTime());
java.util.Date 就是在除了SQL语句的情况下面使用
java.sql.Date 是针对SQL语句使用的,它只包含日期而没有时间部分
调用存储过程,设置参数 setTimestamp/getTimestamp
java.sql.Timestamp captureDate = new java.sql.Timestamp(captureTime.getTime());
System.out.println("Ptimestamp:" + captureDate); //Ptimestamp:2018-03-08 09:42:21.0
cstmt.setTimestamp(2, captureDate);
一般使用之间格式转换:
非常重要:formatTime.parse(formatTime.format(mapException.get("GETDATATIME")));//转换格式要匹配
SimpleDateFormat formatTime = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
List<Map<String, Object>> listExceptions = oracleDao.getIsThereExceptionsP();for (Map<String, Object> mapException : listExceptions) {
System.out.println(mapException.get("GETDATATIME").toString());
String captureTimeS = formatTime.format(mapException.get("GETDATATIME"));
System.out.println(captureTimeS);
captureTime = formatTime.parse(captureTimeS);
System.out.println("parse:" + captureTime);
java.sql.Timestamp timestamp = new Timestamp(captureTime.getTime());
System.out.println("timestamp:" + timestamp);
System.out.println("timestampFormat:" + formatTime.format(timestamp));