Search code examples
javajpaspring-data-jpasql-timestamp

Timestamp Time is changed after fetching the record


I am facing issue while fetching record, The timestamp value is changed after fetching from DB.

In my Oracle DB the column value is "19-OCT-22 02.15.00.000000000 AM" but after fetching it comes as "2022.10.19 00:15:00"

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd HH:mm:ss")
    private Timestamp startDate; 

I am using JPA repository with springboot to fetch the records.


Solution

  • LocalDateTime worked now.

    @Column(name = "STARTDATE") 
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd HH:mm:ss") 
    private LocalDateTime startDate; 
    

    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 
    LocalDateTime timestamp = LocalDateTime.parse(fromDate, format); 
    List<JobName> list = repository.findJobNameBylastTime(timestamp);