问题:作业

import java.time.LocalDate; import java.time.LocalTime; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.LocalDateTime; import java.util.Scanner; public class Demo10 { public static void main(String[] args) throws Exception { // 输入: Scanner scanner = new Scanner(System.in); System.out.print("Departure date (yyyy-MM-dd): "); String departureDate = scanner.nextLine(); System.out.print("Departure time (HH:mm): "); String departureTime = scanner.nextLine(); scanner.close(); // TODO: 飞行12小时15分钟,计算到达的当地时间: LocalDate dt = LocalDate.parse(departureDate); LocalTime time = LocalTime.parse(departureTime); LocalDateTime dtime = LocalDateTime.of(dt,time); LocalDateTime arrival = dtime.plusHours(12).plusMinutes(15); ZonedDateTime bjArrival = arrival.atZone(ZoneId.systemDefault()); ZonedDateTime usaArrivalDateTime  = bjArrival.withZoneSameInstant(ZoneId.of("America/New_York")); LocalDate arrivalDate = usaArrivalDateTime.toLocalDate(); LocalTime arrivalTime = usaArrivalDateTime.toLocalTime(); // 输出: System.out.println("Arrival date: " + arrivalDate); System.out.println("Arrival time: " + arrivalTime); } }
  • 1

您当前正在使用不支持HTML5的低版本浏览器,飞扬学院需要支持HTML5的浏览器才能为您提供更好的学习体验。请使用支持HTML5的Chrome浏览器Firefox浏览器或最新版本的IE浏览器