前后端时间格式交互

2019-07-24  本文已影响0人  9186720dca2f

前后端时间格式交互(spring boot + vue.js + element-ui)

GMT/UTC时间格式:yyyy-MM-dd'T'HH:mm:ss.SSSZ

前后端一般的时间交互格式:yyyy-MM-dd HH:mm:ss

前端日期转化:使用format指定输入框的格式;使用value-format指定绑定值的格式。

参考自:https://element.eleme.cn/#/zh-CN/component/date-picker#ri-qi-ge-shi

后端接收:注解@JsonFormat主要是后端到前端的时间格式的转换,注解@DataFormat主要是前端到后端的时间格式的转换

参考自:https://www.cnblogs.com/mracale/p/9828346.html

element-ui代码:

<el-form-item label="开始时间" prop="startTime">

    <el-date-pickerv-model="dataForm.startTime" type="datetime"

        placeholder="选择日期时间" 

        value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss"

        :picker-options="pickerOptions">

    </el-date-picker>

</el-form-item>

后端代码:

1.使用类接受参数

@DateTimeFormat(pattern = "yyyy-MM-dd")

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")

private LocalDateTime startTime;//或者申明为Date对象

2.方法直接接受参数

@GetMapping("/test")

public R test(@DateTimeFormat(pattern="yyyy-MM-dd")

                     @RequestParam("orderTime") LocalDate orderTime) {

    return new R();

}

上一篇 下一篇

猜你喜欢

热点阅读