package com.java.Date.www;
import java.text.DateFormat;
import java.text.Format;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class DateDmeo2 {
public static void main(String[] args) {
Date data=new Date();
// String str=DateFormat.getDateInstance(DateFormat.FULL).format(data);
// Calendar str=Calendar.getInstance();
// int year=str.get(Calendar.YEAR);
// int mouth=str.get(Calendar.MONDAY);
// int day=str.get(Calendar.DAY_OF_MONTH);
// System.out.println(year+"年"+mouth+"月"+day+"日");
System.out.println("------------------设置日期并且比较两个日期的大小----------------------------------------");
Calendar c=Calendar.getInstance();
Calendar c1=Calendar.getInstance();
c.set(2012, 3, 27);
c1.set(2013, 7, 29);
// System.out.println(c.getTimeInMillis());
long s=bijiao(c,c1);
System.out.println(s);
System.out.println("--------------给定那个年份并且判断2月有几天-------------------------------");
//创建一个Scanner对象
System.out.println("请输入你的年份");
Scanner year1=new Scanner(System.in);
System.out.println("请输入你的月份");
Scanner month1=new Scanner(System.in);
System.out.println("请输入你的几号");
Scanner date1=new Scanner(System.in);
int year=year1.nextInt();
int month=month1.nextInt();
int date=date1.nextInt();
//定义个新的Scalendar 的日期默认值
Calendar c2=Calendar.getInstance();
//添加日期进入Scalendar;
c2.set(year, month, date);
String i=getday(year);
System.out.println(i);
}
private static String getday(int year) {
if(year%4==0&&year%100!=0||year%400==0){
return "这个2月有29天";
}else{
return "这个2月有28天";
}
}
private static long bijiao(Calendar c, Calendar c1) {
if(c.compareTo(c1)>0){
return c.getTimeInMillis()-c1.getTimeInMillis();
}else if(c.compareTo(c1)<0){
return c1.getTimeInMillis()-c.getTimeInMillis();
}
return 0;
}
}