I want to convert pre Java8 like below.
DateFormat formatter = new SimpleDateFormat(timestampPattern, locale);
Date dt = formatter.parse(timestamp);
Date currentDateTime = getCurrentTime();
To Java 8 code to support more than 3 digits in milliseconds. I found ways to do that using the following simple code.
String parsedate="2016-03-16 01:14:21.6739";
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSS");
LocalDateTime newdate = LocalDateTime.parse(parsedate, dateTimeFormatter);
Problem with above code is that you have to know specific class before parsing it like if it contains only date in you have to use LocalDate and if only time LocalTime and if date + time + zone you have to use ZonedDateTime.
My problem is that I don't know timestampPattern or timestamp(Given in pre Java8 code snippet) before hand(as it is user input) hence can't choose subclass in my code. Is there any better way for this?