林尼治标准时间转换为yyyy-MM-dd HH:mm:ss,elementUI日期时间选择器传给后台
elementUI时间日期选择器选择完传给后台的是林尼治标准时间
直接将格林尼治时间作参数传到下面的方法,下面的方法直接贴,
// 格林尼治转换yyyy-MM-dd HH:mm:ss
GMTToStr (time) {
console.log('time:' + time)
let date = new Date(time)
let minutes
let hours
let month
let second
let relDate
if (date.getSeconds() < 10) {
second = '0' + date.getSeconds()
} else {
second = date.getSeconds()
}
if (date.getMinutes() < 10) {
minutes = '0' + date.getMinutes()
} else {
minutes = date.getMinutes()
}
if (date.getHours() < 10) {
hours = '0' + date.getHours()
} else {
hours = date.getHours()
}
if (date.getMonth() < 10) {
month = '0' + (date.getMonth() + 1)
} else {
month = date.getMonth() + 1
}
if (date.getDate() < 10) {
relDate = '0' + date.getDate()
} else {
relDate = date.getDate()
}
let Str = date.getFullYear() + '-' +
month + '-' +
relDate + ' ' +
hours + ':' +
minutes + ':' +
second
return Str //返回的就是yyyy-MM-dd HH:mm:ss格式,上面time就是你传入的林尼治标准时间
},
网上查的有不少,但还是有点问题,还有后台接收的属性,需要添加注解:@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
类似:

我用的是String,Date的话可以试试
参考:https://blog.csdn.net/zengshuqin/article/details/23689253
赞 (0)
