1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public class Test {
public static void main(String args[]) {
ZoneId leavingZone = ZoneId.systemDefault(); // pour prendre la zone par défaut de ton système
// ou pour indiquer une zone explicitement, ZoneId leavingZone = ZoneId.of("Europe/Paris");
// pour avoir la liste des ids de zone disponbiles : System.out.println(ZoneId.getAvailableZoneIds());
ZonedDateTime departure = ZonedDateTime.of(
LocalDate.of(2007, Month.DECEMBER, 3),
LocalTime.of(10, 15),
leavingZone);
// ou ZonedDateTime departure = ZonedDateTime.of(LocalDateTime.of(2007, Month.DECEMBER, 3, 10, 15), leavingZone);
// ou ZonedDateTime departure = ZonedDateTime.of(2007, Month.DECEMBER.getValue(), 3, 10, 15, 0, 0, leavingZone);
try {
DateTimeFormatter format = DateTimeFormatter
.ofPattern("MMM d yyyy hh:mm a");
String out = departure.format(format);
System.out.printf("LEAVING: %s (%s)%n", out, leavingZone);
} catch (DateTimeException exc) {
System.out.printf("%s can't be formatted!%n", departure);
throw exc;
}
/**
* The output for this example, which prints both the arrival and
* departure time, is as follows:
*
* LEAVING: Jul 20 2013 07:30 PM (America/Los_Angeles) ARRIVING: Jul 21
* 2013 10:20 PM (Asia/Tokyo)
**/
}
} |
Partager