I'm using Java 8 and I have a string in my .txt
file which I want to convert into a LocalDateTime
object.
String time1 = "2017-10-06T17:48:23.558";
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("dd.MM.yyyy. HH:mm:ss");
LocalDateTime alarmTime = LocalDateTime.parse(time1, formatter1);
System.out.println(time1);
This gives me this exception:
Exception in thread "main" java.time.format.DateTimeParseException: Text '2017-10-06T17:48:23.558' could not be parsed at index 2
at java.time.format.DateTimeFormatter.parseResolved0(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.LocalDateTime.parse(Unknown Source)
Any ideas?
P.S. Note that this:
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.yyyy. HH:mm:ss");
DateTime dt = formatter.parseDateTime(string);
doesn't work in Java 8.
Edit: I didn't make the question clear enough, my bad:
I have this string in my .txt
file, and I need to convert it to LocalDateTime
object in order to save it into a class object, but I need it in the format stated in order to print it out inside a table. I don't want it to print out in the raw format that is "2017-10-06T17:48:23.558"
. I want it to print out something like this: "10.06.2017. 17:48:23"