问题:作业

Jealous Guy...发布 问题来源
写得有点复杂 ``` package com.feiyangedu.time; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Scanner; public class Main { 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(); // TODO: 飞行12小时15分钟,计算到达的当地时间: LocalDate departureD = LocalDate.parse(departureDate); LocalTime departureT = LocalTime.parse(departureTime); LocalDateTime beijing = LocalDateTime.of(departureD, departureT); ZonedDateTime bj = beijing.atZone(ZoneId.systemDefault()); ZonedDateTime ny = bj.withZoneSameInstant(ZoneId.of("America/New_York")); ny = ny.plusHours(12); ny = ny.plusMinutes(15); LocalDate arrivalDate = ny.toLocalDate(); LocalTime arrivalTime = ny.toLocalTime(); // 输出: System.out.println("Arrival date: " + arrivalDate); System.out.println("Arrival time: " + arrivalTime); } } ```
Imhandsomeguy...发布
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(); // TODO: 飞行12小时15分钟,计算到达的当地时间: // 1.将输入的日期时间转换为LocalDateTime LocalDateTime ldt = LocalDateTime.parse(departureDate+"T"+departureTime); // 2.将时间增加12小时15分钟 LocalDateTime plusHour = ldt.plusHours(12); LocalDateTime plusMinute = plusHour.plusMinutes(15); // 3.将LocalDateTime关联北京时区 ZonedDateTime bj = plusMinute.atZone(ZoneId.systemDefault()); // 4.将北京时区转换为纽约时区 ZonedDateTime ny = bj.withZoneSameInstant(ZoneId.of("America/New_York")); // 5.拆分日期与时间 LocalDate arrivalDate = ny.toLocalDate(); LocalTime arrivalTime = ny.toLocalTime(); // 输出: System.out.println("Arrival date: " + arrivalDate); System.out.println("Arrival time: " + arrivalTime);
生生不息...发布
LocalDateTime ldt = LocalDateTime.parse(departureDate+"T"+departureTime);这个"T"怎么解释呀?
  • 1

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