posted 8 years ago
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!
[code=java]
try {
//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);
timer.schedule(new ATask(), aDate);
} catch (DateTimeException e) {
System.exit(0);
}
[/code]