je tente de convertir la chaîne de JSON à ZonedDateTime commeImpossible de convertir la chaîne à 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;
}
et toujours obtenir l'erreur
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)
Je veux obtenir la différence entre ces deux date. J'ai essayé SimpleDateFormat
mais il obtiendra le résultat d'erreur, pour les usines.
Il ne fait pas beaucoup de sens pour créer un 'Parser', puis appelez immédiatement' ISO_DATE' dessus. –
sans 'Parser' et 'ISO_DATE' obtiendra également DateTimePareseException –
Ce que je dis est que' DateTimeFormatter.ofPattern (pattern) .ISO_DATE' est équivalent à 'DateTimeFormatter.ISO_DATE'. –