publicstaticvoid main(String[] args) {
TimeZone tz = TimeZone.getDefault(); // Use "GMT" to avoid any surprises related to offset // transitions.
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
try { for (String[] item : data) {
test(item[0], item[1]);
}
} finally { // Restore the default time zone
TimeZone.setDefault(tz);
}
if (errorCount > 0) { thrownew RuntimeException("Failed with " + errorCount + " error(s).");
}
}
privatestaticvoid test(String pattern, String src) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
sdf.setLenient(false);
ParsePosition pos = new ParsePosition(0);
System.out.printf("parse: \"%s\" with \"%s\"", src, pattern);
Date date = sdf.parse(src, pos);
System.out.printf(": date = %s, errorIndex = %d", date, pos.getErrorIndex()); if (date != null || pos.getErrorIndex() == -1) {
System.out.println(": failed");
errorCount++;
} else {
System.out.println(": passed");
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.