How can we convert com.datastax.driver.core.LocalDate to YYYY/MM/DD format?

973 Views Asked by At

I want to convert the com.datastax.driver.core.LocalDate object returned by the API to yyyy-MM-dd format. How can I do that?

I tried below code but it is not working for com.datastax.driver.core.LocalDate-

 @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd") 
 String date;
1

There are 1 best solutions below

0
On

I am not sure how you can do it using annotation but below is one way of explicitly converting com.datastax.driver.core.LocalDate to yyyy-MM-dd format -

java.util.Date dateObj = new java.util.Date(localDate.getMillisSinceEpoch());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(dateObj);