Невозможно получить Instant из TemporalAccessor: {}, ISO разрешено в 2024-04-25T14:32:42 типа java.time.format.ParsedJAVA

Программисты JAVA общаются здесь
Anonymous
Невозможно получить Instant из TemporalAccessor: {}, ISO разрешено в 2024-04-25T14:32:42 типа java.time.format.Parsed

Сообщение Anonymous »

У меня есть Java-программа, которая преобразует строку в объект Instant.

Код: Выделить всё

import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

public class JenkinsBuildDateFormatApp {
public static void main(String[] args) {
String extractedDate = "Apr 25, 2024, 2:32:42 PM";
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MMM dd, yyyy, h:mm:ss a");
TemporalAccessor ta = dtf.parse(extractedDate);
System.out.println(Instant.from(ta));
}
}
Когда я запускаю программу, я получаю ошибку ниже -

Код: Выделить всё

Exception in thread "main" java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: > {},ISO resolved to 2024-04-25T14:32:42 of type java.time.format.Parsed
at java.base/java.time.Instant.from(Instant.java:381)
at JenkinsBuildDateFormatApp.main(JenkinsBuildDateFormatApp.java:12)
Caused by: java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: InstantSeconds
at java.base/java.time.format.Parsed.getLong(Parsed.java:215)
at java.base/java.time.Instant.from(Instant.java:376)
... 1 more
Process finished with exit code 1
Как устранить ошибку?


Подробнее здесь: https://stackoverflow.com/questions/783 ... 4-04-25t14

Вернуться в «JAVA»