最近搜索

控制器接受 日期 并且 格式化日期 格式化时间

浏览:493
管理员 2019-09-07 15:00



初始化日期格式



	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); // true:允许输入空值,false:不能为空值
    }	



这种方法抛弃了,可以使用下面这种。 springboot + mybatisplus

@TableField(value = "yuyue_date1")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")//不加timezone = "GMT+8"时间 好像不对。小时和分不对。
private Date yuyueDate1;
@TableField(value = "yuyue_date2")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")//不加timezone = "GMT+8"时间 好像不对。小时和分不对。
private Date yuyueDate2;



@JsonSerialize(using = CustomDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")  这是接受的日期。必须加这个gmt-8
private Date founddate;// 发现日期


联系站长

站长微信:xiaomao0055

站长QQ:14496453