欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java日期属性json格式化

程序员文章站 2022-07-13 09:03:00
...
import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;

public class User {
	
	private Long id;
	private String username;
	// 日期类型输出到页面格式
	@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")  
	// 页面字符串格式化为日期
	@DateTimeFormat(pattern="yyyy-MM-dd") 
	// 代码中转JSON格式字符串
	@JSONField(format="yyyyMMdd")
	private Date birthday;
	private Integer status;
	
	//getter setter 略
	
}

 

 

相关标签: java