日期工具類積累

2021-10-07 21:45:03 字數 2250 閱讀 9743

以下的時間方法是我自己親測沒有問題的,做下記錄:

/** 獲取當前系統時間的年份*/

public

static integer getnowyear()

/** 獲取系統時間的當年第一天日期*/

public

static string getyearfirst()

/** 獲取系統時間的當年最後一天日期*/

public

static string getyearlast()

/** 獲得該月第一天 */

public

static string getfirstdayofmonth

(int month)

/** 獲得該月最後一天 */

public

static string getlastdayofmonth

(int month)

else

// 設定日曆中月份的最大天數

cal.

set(calendar.day_of_month, lastday)

;// 格式化日期

******dateformat sdf =

new******dateformat

("yyyy-mm-dd");

string lastdayofmonth = sdf.

format

(cal.

gettime()

)+" 23:59:59"

;return lastdayofmonth;

}

/*按照系統時間12個月每月的頭一天與最後一天/

public

static monthparam getmonthparam()

;for

(integer integer : time)

else

if(integer ==2)

else

if(integer ==3)

else

if(integer ==4)

else

if(integer ==5)

else

if(integer ==6)

else

if(integer ==7)

else

if(integer ==8)

else

if(integer ==9)

else

if(integer ==10)

else

if(integer ==11)

else

if(integer ==12)

}return monthparam;

}

/*格式化日期 yyyy-mm-dd hh:mi:ss/

public

static string formatdate

(date date)

//hh返回的是24小時制的時間!! hh返回的是12小時制的時間!!

******dateformat f =

new******dateformat

(「yyyy-mm-dd hh:mm:ss」)

; string sdate = f.

format

(date)

;return sdate;

}

/** 格式化日期 yyyy-mm-dd*/

public

static string formattodate

(date date)

******dateformat f =

new******dateformat

("yyyy-mm-dd");

string sdate = f.

format

(date)

;return sdate;

}

//main方法測試

public

static

void

main

(string[

] args)

;for

(integer integer : time)

}

日期工具類

import math from datetime import datetime,timedelta class calendarutils 日期工具類 staticmethod defdelta day delta 0 param delta 偏移量 return 0今天,1昨天,2前天,1明天...

date 日期工具類

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

DateUtil日期工具類

public class dateutil category 返回int的值,表示兩個指定日期間的時間間隔數目 public static int datediff string interval,date date1,date date2 throws exception interval 季 i...