时间日期的前后台不一致问题,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
就可以了。