题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
import java.time.LocalDate;
import java.util.Scanner;
/**
* @author hll[yellowdradra@foxmail.com]
* @since 2023-03-24 14:30
**/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
System.out.println(LocalDate.of(year, month, day).getDayOfYear());
// System.out.println(dayOfYear(year, month, day));
}
// public static int dayOfYear(int year, int month, int day) {
// return firstDayOfYear(isLeapYear(year), month) + day - 1;
// }
// public static boolean isLeapYear(long prolepticYear) {
// return ((prolepticYear & 3) == 0)
// && ((prolepticYear % 100) != 0 || (prolepticYear % 400) == 0);
// }
// public static int firstDayOfYear(boolean leapYear, int month) {
// int leap = leapYear ? 1 : 0;
// return switch (month) {
// case 1 -> 1;
// case 2 -> 32;
// case 3 -> 60 + leap;
// case 4 -> 91 + leap;
// case 5 -> 121 + leap;
// case 6 -> 152 + leap;
// case 7 -> 182 + leap;
// case 8 -> 213 + leap;
// case 9 -> 244 + leap;
// case 10 -> 274 + leap;
// case 11 -> 305 + leap;
// // 12
// default -> 335 + leap;
// };
// }
}
