時間工具類

2021-08-20 13:49:44 字數 3403 閱讀 1043

// 獲取當前時間(年月日時分秒)

@test

public void nowdate()

// 獲取任意過去或者未來的現在時間

@test

public void pastorfuturedate()

// 獲取任意兩個時間之間相差多少秒

@test

public void anytwotimedifference() throws parseexception

// 獲取上個月的現在時間

@test

public void anymonthdate()

// 判斷任意一天是星期幾

@test

public void determinethedayoftheweek() throws parseexception

// 判斷任意一天是該年的第幾天

@test

public void daysofyear() throws parseexception

// 判斷任意一天是該年的第幾周

// 星期天是乙個星期的第一天

@test

public void weeksof() throws parseexception

// 判斷指定日期當月有多少天

@test

public void totalday() throws parseexception

// 輸出兩個時間段所有的時間

@test

public void findday()

system.out.println(daylist); // 輸出是:[2018-08-06, 2018-08-07, 2018-08-08, 2018-08-09, 2018-08-10]

}// 指定時間加上小時,天等

@test

public void adadad() throws parseexception ;

/* * 將時間戳轉換為時間

*/public static string stamptodate(string s)catch (exception e)

return res;

} /**

* 得到當前日期字串 格式(yyyy-mm-dd)

*/public static string getdate()

/*** 得到當前日期字串 格式(yyyy-mm-dd) pattern可以為:"yyyy-mm-dd" "hh:mm:ss" "e"

*/public static string getdate(string pattern)

/*** 得到日期字串 預設格式(yyyy-mm-dd) pattern可以為:"yyyy-mm-dd" "hh:mm:ss" "e"

*/public static string formatdate(date date, object... pattern) else

return formatdate;

} /**

* 得到日期時間字串,轉換格式(yyyy-mm-dd hh:mm:ss)

*/public static string formatdatetime(date date)

/*** 得到當前時間字串 格式(hh:mm:ss)

*/public static string gettime()

/*** 得到當前日期和時間字串 格式(yyyy-mm-dd hh:mm:ss)

*/public static string getdatetime()

/*** 得到當前年份字串 格式(yyyy)

*/public static string getyear()

/*** 得到當前月份字串 格式(mm)

*/public static string getmonth()

/*** 得到當天字串 格式(dd)

*/public static string getday()

/*** 得到當前星期字串 格式(e)星期幾

*/public static string getweek()

/*** 日期型字串轉化為日期 格式

*/public static date parsedate(object str)

try catch (parseexception e)

} /**

* 獲取過去的天數

* * @param date

* @return

*/public static long pastdays(date date)

/*** 獲取過去的小時

* * @param date

* @return

*/public static long pasthour(date date)

/*** 獲取過去的分鐘

* * @param date

* @return

*/public static long pastminutes(date date)

/*** 轉換為時間(天,時:分:秒.毫秒)

* * @param timemillis

* @return

*/public static string formatdatetime(long timemillis)

/*** 獲取兩個日期之間的天數

* * @param before

* @param after

* @return

*/public static double getdistanceoftwodate(date before, date after)

/**

* 將乙個時間戳轉換成提示性時間字串,如剛剛,1秒前

* * @param before 時間格式化

* @return

*/

public static string converttimetoformat(date before) else if (time >= 60 && time < 3600) else if (time >= 3600 && time < 3600 * 24) else if (time >= 3600 * 24 && time < 3600 * 24 * 30) else if (time >= 3600 * 24 * 30 && time < 3600 * 24 * 30 * 12) else if (time >= 3600 * 24 * 30 * 12) else

} /**

* @param args

* @throws parseexception

*/public static void main(string args) throws parseexception

}

時間工具類

1 根據日期獲取當天是週幾 根據日期獲取當天是週幾 param datetime 日期 return 週幾 author lu since 1.0,2020年7月30日 public static string getweekofdate date datetime calendar calenda...

時間工具類

public class timeutils 獲取帶連線符的日期型別 return public static string getcurrentnormaldate 獲取當年的年份 return public static int getcurrentyear 獲取當年的月份 return pub...

時間工具類

隨手記錄 string轉date時間 param time 時間字串 param format 格式 return author ydl date 2020 09 17 public static date formatdate string time,string format dateforma...