1. Vue前端修改实例代码
//示例代码:
<template>
<div>
<a-date-picker show-time placeholder="Select Time" @change="onChange" @ok="onOk" />
<br />
<a-range-picker
:show-time="{ format: 'HH:mm' }"
format="YYYY-MM-DD HH:mm"
:placeholder="['Start Time', 'End Time']"
@change="onChange"
@ok="onOk"
/>
</div>
</template>
<script>
export default {
methods: {
onChange(value, dateString) {
console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString);
},
onOk(value) {
console.log('onOk: ', value);
},
},
};
</script>
2. Java类字段添加JSON的时区注解
/**
* 添加带时间范围查询字段
* 2021.06.25 Asher Huang
*/
//添加@JsonFormat解决前端传递过来的时间格式,之前传递的是日期,现在改为时间日期格式。带上时区,解决时差8小时的问题
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date beginDt;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date endDt;
3. application.properties配置文件中加配置
## default config
spring:
jackson:
time-zone: "GMT+8"
date-format: "yyyy-MM-dd HH:mm:ss"