I am trying to convert Current Time Stamp into "dd-MMM-yy HH:mm:ss a" format but not getting an expected output.
My Expected output in java.sql.Timestamp = 08-May-20 14:50:43 PM I want to store it in Java.sql.Timestamp variable but getting output in a different format
Note - I tried approx all the solutions on SO. I request you to please suggest whats doing wrong in my code.
I am trying to convert String to java.sql.Timestamp as mention above format.
public class TimeExample {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
System.out.println("Before : " + now);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MMM-yy HH:mm:ss a");
String formatDateTime = now.format(formatter);
System.out.println("formated --- " + formatDateTime);
LocalDateTime localDateTime = LocalDateTime.parse(formatDateTime, formatter);
System.out.println("DD : " + localDateTime);
Timestamp timeStamp = Timestamp.valueOf(localDateTime);
System.out.println("timeStamp : " + timeStamp);
}
}
>**My Expected output in java.sql.Timestamp = 08-May-20 14:50:43 PM**
> output - Before : 2020-05-08T14:50:43.053
> formated --- 08-May-20 14:50:43 PM
> DD : 2020-05-08T14:50:43
> timeStamp : 2020-05-08 14:50:43.0