I am using a DateSpinner to get a date and time to begin a task. I am trying to use java.time, but the error I am getting when converting to string through the formatter tells me that the getValue method is outputting a util.date, incompatible with java.time. Is there a way to get a string value from DateSpinner that is compatible with java.time? Or should I not use java.time and go back to using the older util.date?
Thanks as always!
//Date and time to start event
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd-yy hh:mm a");
String aTime = formatter.format(aSpinner.getValue()); // this is the problem!
jTextArea1.append("date is " + aTime);
LocalDateTime aDateTime = LocalDateTime.parse(aTime, formatter);
Instant instant = aDateTime.atZone(ZoneId.systemDefault()).toInstant();
Date aDate = Date.from(instant);
In this case I don't see why you need to use java.time when you convert the LocalDateTime into a Date anyway. But you can also do the opposite - turn the Date into an Instant, then convert that into a LocalDateTime.