// Test with default format: by default date is in UTC.
System.out.println("Testing with UTC");
test(() -> new TimeStamp(ZoneOffset.UTC));
// Change LogManager configuration so that new // XMLFormatter prints date in the pre Java 9 local zone format try {
Properties props = new Properties();
props.setProperty("java.util.logging.XMLFormatter.useInstant", "false");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
props.store(baos, "");
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
LogManager.getLogManager().updateConfiguration(bais, (k) -> (o,n) -> n!=null?n:o);
} catch (IOException io) { thrownew RuntimeException(io);
}
// re test with the old format: date will be in the local time zone.
System.out.println("Testing with old format");
test(() -> new TimeStamp(ZoneId.systemDefault()));
TimeStamp t1 = timeStampSupplier.get(); int year1 = t1.getYear();
LogRecord record = new LogRecord(Level.INFO, "test");
XMLFormatter formatter = new XMLFormatter(); final String formatted = formatter.format(record);
System.out.println(formatted);
final TimeStamp t2 = timeStampSupplier.get(); finalint year2 = t2.getYear(); if (year2 < 1900) { thrownew Error("Invalid system year: " + year2);
}
final StringBuilder buf2 = new StringBuilder()
.append("<date>").append(year2).append("-"); if (!formatted.contains(buf2.toString())) {
StringBuilder buf1 = new StringBuilder()
.append("<date>").append(year1).append("-"); if (formatted.contains(buf1) && year2 == year1 + 1
&& t2.isJanuaryFirst()) { // Oh! The year just switched in the midst of the test...
System.out.println("Happy new year!");
} else { thrownew Error("Expected year " + year2
+ " not found in log:\n" + formatted);
}
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-10)
¤
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.