题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class Main { public static void main(String[] args) throws ParseException { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String input = in.nextLine(); String begin = input.split(" ")[0] + " 1 1"; SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd"); Date date1 = format.parse(input); Date date2 = format.parse(begin); System.out.println((date1.getTime() - date2.getTime() + 1000 * 60 * 60 * 24) / 1000 / 60 / 60 / 24); } } }