java中Calendar类中给出了求第几天第几周的方法的,所以直接引用即可。
Calendar ca = Calendar.getInstance();//创建一个日期实例
ca.setTime(new Date());//实例化一个日期
System.out.println(ca.get(Calendar.DAY_OF_YEAR));//获取是第多少天
System.out.println(ca.get(Calendar.WEEK_OF_YEAR));//获取是第几周
备注:此方法提供了很多方法,如查月,日等等。
Calendar ca = Calendar.getInstance();
ca.setTime(new Date());
System.out.println(ca.get(Calendar.DAY_OF_YEAR));
System.out.println(ca.get(Calendar.WEEK_OF_YEAR));
你试试Calendar这个是java.util包里的
public static void main(String[] args) {
System.out.println("请输入年、月、日");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt();
int d=0,e=0,num = 0;
int[] list1 = { 1, 3, 5, 7, 8, 10, 12 };
int[] list2 = { 4, 6, 9, 11 };
//月份1(31天)
for (int i = 0; b > list1[i]; i++) {
d = d+1;
}
//月份2(30)
for (int j = 0; b > list2[j]; j++) {
e = e+1;
if (b == list2[(list2.length)-1]) {
e=(list2.length)-1;
break;
}else if(b >list2[(list2.length)-1]) {
e=(list2.length);
break;
}
}
if ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0) {
if(b>2) {num = d * 31 + e * 30 + 29 + c;}
else {num = d * 31 + e * 30 + c;}
} else {
if(b>2) {num = d * 31 + e * 30 + 28 + c;}
else {num = d * 31 + e * 30 + c;}
}
System.err.println("输入的日期为"+a+"年的第" + num + "天");
}