用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

日历大全

2016-11-22 作者: java程序设计举报

[java]代码库

package com.days;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Test {
	int startYear;
	int endYear;
public Test(int startYear, int endYear){
	this.startYear=startYear;
	this.endYear=endYear;
}
public long howDays(){
	long day=0;
	for(int year=startYear;year<=endYear;year++){
		if(year%4==0&&year%100!=0||year%100==0){
			day+=366;
		}else{
			day+=365;
		}
	}
	return day;
	
}
public long howYears(){
	return endYear-startYear+1;
}
int direction=1;
String str="";
public void timeRili(){
	long days=howDays();
	int startWeek=startYearStartMonthStartDay();
	for(int year=startYear;year<=endYear;year++){
		System.out.println("\n"+year+"年");
		int monthDay=0;
		for(int month=1;month<=12;month++){
			System.out.println("\n"+month+"月");
			switch(month){
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				monthDay=31;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				monthDay=30;
				break;
			case 2:
				if(year%4==0&&year%100!=0||year%100==0){
					monthDay=29;
				}else{
					monthDay=28;
				}
				break;
				default:
					break;
			}
			if(year==startYear&&month==1){
				System.out.println("日\t一\t二\t三\t四\t五\t六");
				for(int i=1-startWeek;i<=monthDay;i++){
					int kongQue=i;
					if(i<=0){
						str+="\t";
					}else{
						str+=kongQue+"\t";
					}
					if(direction==7){
						System.out.println(str);
						str="";
						direction=0;
					}
					direction++;
				}
			}else{
				System.out.println("日\t一\t二\t三\t四\t五\t六");
				for(int i=1;i<=monthDay;i++){
					int kongQue=i;
					str+=kongQue+"\t";
					if(direction==7){
						System.out.println(str);
						str="";
						direction=0;
					}else{
						if(year==endYear&&month==12&&i==31){
							if(direction<7){
								System.out.println(str);
								str="";
								direction=0;
							}
						}
					}
					direction++;
				}
			}
		}
	}
}
  int startYearStartMonthStartDay() {
	SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
	Date date=null;
	try{
		date = simpleDateFormat.parse(startYear + "-01-01");
		
	}catch (ParseException e){
		e.printStackTrace();
	}
	Calendar ca = Calendar.getInstance();
	ca.setTime(date);
	return ca.get(Calendar.DAY_OF_WEEK) - 1;
	}
}





package com.days;

import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		System.out.println("请输入开始的年份:");
		Scanner scanner=new Scanner(System.in);
		int startYear=scanner.nextInt();
		System.out.println("请输入结束的年份:");
		int endYear=scanner.nextInt();
		Test test=new Test(startYear, endYear);
		System.out.println("多少年:"+test.howYears());
		System.out.println("多少天:"+test.howDays());
		System.out.println("开始年的第一天是星期几:"+test.startYearStartMonthStartDay());
		test.timeRili();
		Test test1=new Test(endYear, endYear);
	}

}


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...