System.out.println("键盘录入一个格式为: 年 月 日 的日期");
String s= new Scanner(System.in).next();//获取键盘录入
SimpleDateFormat str =new SimpleDateFormat("yyyy年MM月dd日"); //把String转换成Date格式,并确定输入格式
Date date = str.parse(s);//调用parse方法,把字符串转换成日期对象
Date day = new Date();//获取今天的日期
long dateDate = date.getTime();
long dayDate = day.getTime();
long xiangcha = dayDate-dateDate;
System.out.println("到今天已经活了"+xiangcha/1000/60/60/24+"天");
Calendar c = Calendar.getInstance();//实例化Calendar
c.setTime(date);//将实例化日期传入
c.set(c.get(Calendar.YEAR),2,1);//设置日期规则 . c.get(Calendar.YEAR),2,1 //获取输入的年和固定月和日.
c.add(Calendar.DAY_OF_MONTH, -1);//3月1日减一天前一个月的最后一天日期
int day_1 = c.get(Calendar.DAY_OF_MONTH);//get方法获取当天天数的值.
System.out.println("那一年的二月"+day_1+"天");
int temp = (c.get(Calendar.YEAR)- 4)%12;
switch (temp) {
case 0:
System.out.println(c.get(Calendar.YEAR)+"年是鼠年");
break;
case 1:
System.out.println(c.get(Calendar.YEAR)+"年是牛年");
break;
case 2:
System.out.println(c.get(Calendar.YEAR)+"年是虎年");
break;
case 3:
System.out.println(c.get(Calendar.YEAR)+"年是兔年");
break;
case 4:
System.out.println(c.get(Calendar.YEAR)+"年是龙年");
break;
case 5:
System.out.println(c.get(Calendar.YEAR)+"年是蛇年");
break;
case 6:
System.out.println(c.get(Calendar.YEAR)+"年是马年");
break;
case 7:
System.out.println(c.get(Calendar.YEAR)+"年是羊年");
break;
case 8:
System.out.println(c.get(Calendar.YEAR)+"年是猴年");
break;
case 9:
System.out.println(c.get(Calendar.YEAR)+"年是鸡年");
break;
case 10:
System.out.println(c.get(Calendar.YEAR)+"年是狗年");
break;
case 11:
System.out.println(c.get(Calendar.YEAR)+"年是猪年");
break;