java 计算年月日

来源:互联网 发布:户型优化设计 编辑:程序博客网 时间:2024/06/18 01:47

//获得当前年

public int getYear(){

Calendar cal=Calendar.getInstance();

return cal.get(Calendar.YEAR);

}


//获得当前月

public int getMonth(){

Calendar cal=Calendar.getInstance();

return cal.get(Calendar.MONTH)+1;

}


//获得当前月天数

public int getMonthCount(){

int num=0;


switch(getMonth){

case 1:

num=31;

break;

case 2:

if((getYear()%4==0&&getyear()%100!=0)||getYear()%400==0){

if(getMonth()==2){

num=28;

}

else{

if(getmonth()==2){

num=29;

}

}

break;

case 3:

........以下省略,判断到12月

}

}

\}

//xx年-xx月-xx日

public string getMinMonthDate(){

return getYear()+"-"+getMonth()+"-"+"01";

}


2017年-11月 -10日

public string getUpMiddlerDate(){

return getYear()+"-"+getMonth()+"-"+getMonth()/3;

}


2017年-11月-21日


public string getDownMiddleDate(){

return getYear()+"-"+getMonth()+"-"+2*getMonth()/3+1;

}


当月最后一天

请看日期函数分享1