Code: Select all
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
// Append date and time components
builder.append(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
// Append zone text with preferred zones
builder.appendZoneText(TextStyle.SHORT, Set.of(ZoneId.of("Asia/Tokyo"),ZoneId.of("America/Los_Angeles")));
// Create the DateTimeFormatter
DateTimeFormatter formatter = builder.toFormatter();
// Format a date and time
ZonedDateTime dateTime = ZonedDateTime.now();
String formattedText = dateTime.format(formatter);
// Print the formatted text
System.out.println(formattedText);
Was passiert, wenn ich eine Zone bereitstelle, die nicht im bevorzugten Satz ist?