Java.time.format.DateTimeParseException: не удалось проанализировать текст по индексу 21JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Java.time.format.DateTimeParseException: не удалось проанализировать текст по индексу 21

Сообщение Anonymous »

Я получаю значение даты и времени как

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

created_at  '2012-02-22T02:06:58.147Z'
Read-only. The time at which this task was created.
Что предоставляется API Asana

Я использую Java 8 для анализа даты и времени как показано ниже

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

import java.time.*;
import java.time.format.*;

public class Times {

public static void main(String[] args) {
final String dateTime = "2012-02-22T02:06:58.147Z";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'hh:mm:ss.SX");

final ZonedDateTime parsed = ZonedDateTime.parse(dateTime, formatter);
System.out.println(parsed);
}
}
Когда я запускаю это, я получаю следующую ошибку

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

Exception in thread "main" java.time.format.DateTimeParseException: Text '2012-02-22T02:06:58.147Z' could not be parsed at index 21
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1947)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1849)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
at Times.main(Times.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Что здесь не так?

Подробнее здесь: https://stackoverflow.com/questions/358 ... t-index-21
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

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