public dateutil(){}
/*** @see 取得當前日期(格式為:yyyy-mm-dd)
* @return string
*/public string getdate()
/*** @see 取得當前時間(格式為:yyy-mm-dd hh:mm:ss)
* @return string
*/public static string getdatetime()
/*** @see 按指定格式取得當前時間()
* @return string
*/public string gettimeformat(string strformat)
/*** @see 取得指定時間的給定格式()
* @return string
* @throws parseexception
*/public string setdateformat(string mydate,string strformat) throws parseexception
public string formatdatetime(string strdatetime, string strformat)
catch (exception e)
return sdatetime;}
public static calendar parsedatetime(string basedate)
cal.set(yy, mm, dd, hh, mi, ss);
return cal;
}public int getday(string strdate)
public int getmonth(string strdate)
public int getweekday(string strdate)
public string getweekdayname(string strdate)
;int iweek = getweekday(strdate);
iweek = iweek - 1;
return "星期" + mname[iweek];}
public int getyear(string strdate)
public string dateadd(string strdate, int icount, int itype)
else
if(itype == 1)
else
if(itype == 2)
else
if(itype == 3)
else
if(itype == 4)
else
if(itype == 5)
cal.add(ptype, icount);
******dateformat sdf = null;
if(itype <= 2)
sdf = new ******dateformat("yyyy-mm-dd");
else
sdf = new ******dateformat("yyyy-mm-dd hh:mm:ss");
string sdate = sdf.format(cal.gettime());
return sdate;}
public string dateadd(string stroption, int idays, string strstartdate)
public int datediff(string strdatebegin, string strdateend, int itype)
/*****************************************
* @功能 判斷某年是否為閏年
* @return boolean
* @throws parseexception
****************************************/
public boolean isleapyear(int yearnum) else if(yearnum % 400 ==0) else
return isleep;
}/*****************************************
* @功能 計算當前日期某年的第幾周
* @return interger
* @throws parseexception
****************************************/
public int getweeknumofyear()
/*****************************************
* @功能 計算指定日期某年的第幾周
* @return interger
* @throws parseexception
****************************************/
public int getweeknumofyearday(string strdate ) throws parseexception
}/*****************************************
* @功能 計算某年某周的開始日期
* @return interger
* @throws parseexception
****************************************/
public string getyearweekfirstday(int yearnum,int weeknum) throws parseexception
/*****************************************
* @功能 計算某年某月的開始日期
* @return interger
* @throws parseexception
****************************************/
public string getyearmonthfirstday(int yearnum,int monthnum) throws parseexception
/*****************************************
* @功能 計算某年某月的結束日期
* @return interger
* @throws parseexception
****************************************/
public string getyearmonthendday(int yearnum,int monthnum) throws parseexception
if (tempmonth.equals("4") || tempmonth.equals("6") || tempmonth.equals("9")||tempmonth.equals("11"))
if (tempmonth.equals("2")) else
}"tempday:" + tempday);
string tempdate = tempyear + "-" +tempmonth + "-" + tempday;
return setdateformat(tempdate,"yyyy-mm-dd");
JAVA日期處理函式
public class dateutil get current month return public static string getcurrenweek public static void main string args 取得當月天數 public static int getcurr...
Java日期處理
獲取當前系統時間 date d new date system.out.println d.tostring 輸出結果為美式時間格式,用以下辦法轉換成中式時間格式 dateformat sdf new dateformat yyyy mm dd hh mm ss string time sdf.fo...
java 日期處理
日期比較 param date01 param date02 return 如果date01 date02 返回true,否則返回false throws parseexception private boolean datecompare string date01,string date02 c...