'How to convert a TimeStamp in a List<String> to String?

It's my first post,

I have a problem i have a sql.Timestamp in my List and i want to do set the value of a the timestamp in a String

            setModificationDate(listDossier.get(12));

The problem is when i try it i have an

java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.lang.String

I tried to do an setModificationDate(listDossier.get(12).toString()); but i didnt't work too.

https://i.stack.imgur.com/mgFN4.png

setModificationDate is just an String.

Thanks for the help



Solution 1:[1]

Use DateFormatter. Example:

String pattern = "MMM dd, yyyy HH:mm:ss.SSSSSSSS"; 
String timestampAsString = "Nov 12, 2018 13:02:56.12345678"; 
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); 
LocalDateTime localDateTime = LocalDateTime.from(formatter.parse(timestampAsString));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Karthikeyan