時間date工具類

2021-09-01 06:59:36 字數 2720 閱讀 7371

public class datetool

public static date getnow()

public static string getdate()

public static string getym()

public static string getdatetime()

//獲得當前月的上一

public static string getlastmonth(string str,string format) throws parseexception

// 獲得當前月的前兩個月

public static string getlastmonth1(string str,string format) throws parseexception

// 獲得當前月的下乙個月

public static string getlastmonth2(string str,string format) throws parseexception

// 獲得當前日期前

public static string getpredate()

// 獲得當前月的第一

public static string getfirstdayofmonth()

public static string getdatetime(string pattern)

public static string getdatetime(date date, string pattern)

public static int getcurrentyear()

public static int getcurrentmonth()

public static int getcurrentday()

public static date adddays(int days)

public static date adddays(date date, int days)

public static date addmonths(int months)

public static date addmonths(date date, int months)

// 2007-11 to 2007

public static int getyear(string date)

// 2007-11 to 11

public static string getmonth(string date)

// 2007-11 to 2007-11-30

public static string getday(string date)

try else if (month == 1 || month == 3 || month == 5 || month == 7

|| month == 8 || month == 10 || month == 12) else

} catch (exception e)

return null;

}// 2007-01-01 to >=2007-01-01 00:00:00 and <=2007-01-01 23:59:59

public static string getdayall(string date, string flag) else if (flag.equals("end"))

} catch (exception e)

return null;

}/**

* 獲取前一

* * @param curyear

* @return

*/public static string getpreyear(string curyear)

private static date add(date date, int amount, int field)

public static long diffdays(date one, date two)

public static int diffmonths(date one, date two)

public static date parse(string datestr, string pattern) catch (parseexception parseexception)

return date;

}public static string format(date date, string pattern) catch (exception e)

}public static date getmonthlastday()

public static date getmonthlastday(date date)

public static void main(string args) catch (exception e)

}public static final string default_date_format = "yyyy-mm-dd";

public static final string default_datetime_format = "yyyy-mm-dd hh:mm:ss";

public static final int maxyear = 2030; // 下拉列表年度選項的最大

public static final int minyear = 1980; // 下拉列表年度選項的最小

}

Date 時間工具類

問題引出 我們每次用到date時間這個類的時候,時間物件轉化為指定的字串,或者把字串轉化為時間物件,等等相對來說會比較麻煩,下面這個時間工具類提供了各種轉化方法,呼叫相應方法就能得到你想要的答案 public class dateutils return parsestring2date dates...

date 日期工具類

兩個日期相減獲得月份 param startcal param endcal return throws parseexception public static int twodatagetmonth string startcal,string endcal throws parseexcept...

時間工具類

獲取當前時間 年月日時分秒 test public void nowdate 獲取任意過去或者未來的現在時間 test public void pastorfuturedate 獲取任意兩個時間之間相差多少秒 test public void anytwotimedifference throws ...