My requirement is to convert the string "2019-04-25 07:06:42.790" to Date
Object with same format as "2019-04-25 07:06:42.790".
I tried to do this, but it is always giving in String format.
String createDate = "2019-04-25 07:06:42.790";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS", Locale.US);
LocalDateTime localDateTime = LocalDateTime.parse(createDate, formatter);
System.out.println(formatter.format(localDateTime));
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US);
formatter1.setTimeZone(TimeZone.getTimeZone("IST"));
Date date = formatter1.parse(createDate);
System.out.println(date);
String formattedDateString = formatter1.format(date);
System.out.println(formattedDateString);
Output from the above code:
2019-04-25 07:06:42.790
Thu Apr 25 07:06:42 IST 2019
2019-04-25 07:06:42.790