본문 바로가기

Spring Boot

[SpringBoot] DateTime Format

  • Response (서버 -> 클라이언트) 로 전달할 때에는 @JsonFormat 을 사용,
// vo ( Server -> Client )
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime registerDate;

 

※주의 : 엑셀 출력시엔 JsonFormat이 안먹기 때문에 (client에 보낼때 json으로 컨버팅할경우) 그런 경우는 String으로 처리해야함

 

  • Request(클라이언트 -> 서버)로 전달할 때는 @DateTimeFormat 을 사용한다.
    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") // 공백 대신 T를 넣어주거나 (선호)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") // 공백으로 보내도 무관하다.
    @Builder.Default    
    private LocalDateTime endDate = LocalDateTime.now();

 

 

'Spring Boot' 카테고리의 다른 글

springboot + gradle + front-end npm build  (0) 2022.03.16
Spring servlet container 이미지  (0) 2021.09.02
ehCache 설정하기  (0) 2019.08.29
Spring Boot + Logback 설정  (0) 2019.06.20
Spring Boot + Apache 연동  (0) 2019.06.17