私はちょうどはZonedDateTimeに文字列を変換できません:DateTimeParseException
static String getWatchTime(JSONObject aJson, JSONObject bJson) {
long difference = 0 ;
try {
String aTime = aJson.getString("time_utc_8");
String bTime = bJson.getString("time_utc_8");
String pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS";
DateTimeFormatter Parser = DateTimeFormatter.ofPattern(pattern).ISO_DATE;
System.out.println(aTime);
ZonedDateTime a = ZonedDateTime.parse(aTime, Parser);
ZonedDateTime b = ZonedDateTime.parse(bTime, Parser);
ChronoUnit unit = null;
difference = unit.between(a, b);
System.out.println(difference);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String t = difference +"";
return t;
}
のようなJSONからZonedDateTimeに文字列を変換しようと常に
Exception in thread "main" java.time.format.DateTimeParseException: Text '2016-06-28 22:29:44.700228' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2016-06-28T22:29:44.700228 of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.OffsetDateTime.parse(Unknown Source)
at Q2.getWatchTime(Q2.java:321)
at Q2.WatchTime(Q2.java:265)
at Q2.main(Q2.java:31)
エラーを取得し、私はこれらの違いを取得したいです2つの日付。 私はSimpleDateFormat
を試しましたが、ミルのエラー結果が表示されます。
'Parser'を作成し、すぐに' ISO_DATE'を呼び出すのはあまり意味がありません。 –
は 'Parser'と' ISO_DATE'を持たず、DateTimePareseExceptionも取得します。 –
私が言っていることは、 'DateTimeFormatter.ofPattern(pattern).ISO_DATE'は' DateTimeFormatter.ISO_DATE'に相当するということです。 –