import java.util.Date;
public class testshuzu {
public static void main(String[] args) {
// 给定一个日期。算出是一年的第几天。
int sum = 0;
Date d = new Date(2009, 5, 10);// 年份 y 由整数 y - 1900 表示。 月份由从 0 至 11
// 的整数表示;0 是一月、1 是二月等等;因此 11 是十二月。
int year = d.getYear();
int month = d.getMonth();
int day = d.getDate();
int days[] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
sum = days[month - 1] + day;
if (year % 4 == 0 && year % 100 != 0 && month > 2 || year % 400 == 0 && month > 2) {
// 判断是否是闰年
sum++;
}
System.out.println("这是一年的第" + sum + "天");
}
}
1.1对于给定一个出生年月,求这个出生年月是在这一年中的哪一天?
最新推荐文章于 2023-07-10 15:13:11 发布