1.String转Date
package com.gowiny.myclass.articlecat.data;
import java.text.SimpleDateFormat;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
@ControllerAdvice
public class StringToDateConverter {
@InitBinder
public void initBinderDateType(WebDataBinder binder) {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(sdf, true));
}
}
2.Date转String
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
网友评论