1

I am developing service that returning json only needs to show date time and minutes, but it shows everything on time stamp. How to get rid of milliseconds and seconds ?

My model below;

private LocalDateTime processStartDate;

My RowMapper bewlow;

taskList.setProcessStartDate(rs.getTimeStamp("PROCESS_START_DATE").toLocalDateTime());

My Response

private LocalDateTime processStartDate;

My Json Response Using Postman below;

"taskResponseList": [
 {
   "processStartDate" : "2020-02-14T17:30:23.00Z"
 }
]
john mohn
  • 55
  • 1
  • 8

2 Answers2

0

you can remove the milliseconds by using the following line of code.

taskList.setProcessStartDate(rs.getTimeStamp("PROCESS_START_DATE").toLocalDateTime()).withNano(0);

To remove both seconds and milliseconds from the time, you can just use the chorounit to truncate the date:

taskList.setProcessStartDate(rs.getTimeStamp("PROCESS_START_DATE").toLocalDateTime()).truncatedTo(ChronoUnit.MINUTES);

Edited:

Convert it into into the date format by using new Date()

 Date date=new Date(rs.getTimeStamp("PROCESS_START_DATE").toLocalDateTime()).truncatedTo(ChronoUnit.MINUTES); 
taskList.setProcessStartDate(date)

And then use any method to remove the seconds and miliseconds from date

Minal Shah
  • 1,402
  • 1
  • 5
  • 13
0

You could also format the way JSON is returned by adding the following to your Response Object :

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd:HH:mm")
private LocalDateTime processStartDate;