時間日期的前後臺不一致問題,oracle數據庫 插入和查詢的時候拿到的時間和存儲值不一致,今天直接上代碼。
一、前臺格式化代碼
//將後臺傳過來的 日期時間 格式化方法
//顯示完整的 yyyy-mm-dd hh:mm:ss
function formatime(oldDate) {
if(!oldDate){
return;
}
if(typeof(oldDate) === 'string'){
//這裡要注意你的格式是什麼,這個CST不要寫錯了
oldDate = oldDate.replace("CST","GMT+0800");
var now = new Date(oldDate);
var year = now.getFullYear();
var month = now.getMonth()+1;
var day = now.getDate();
var hours = now.getHours();
if(hours <= 9){
hours = "0" + hours;
}
var minutes = now.getMinutes();
if(minutes <= 9){
minutes = "0" + minutes;
}
var seconds = now.getSeconds();
if(seconds <= 9){
seconds = "0" + seconds;
}
if(month <= 9){
month = "0" + month;
}
if(day <= 9){
day = "0" +day;
}
return "" + year + "-" + month + "-" + day
+ " " + hours + ":" + minutes + ":" + seconds + "";
}
}
二、後臺數據庫插入問題
oracle 數據庫在你的 類中 Date 類型上面加上
1. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
2.@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss"
)
這兩個註解
3、在 oracle 插入和查詢數據庫的時候 xml 文件中 date 類型的去掉 jdbcType = date
就可以了。
閱讀更多 LOVER 的文章