時間工具類

2021-10-22 05:52:27 字數 2004 閱讀 9647

隨手記錄

/**

* string轉date時間

** @param time 時間字串

* @param format 格式

* @return

* @author ydl

* @date 2020-09-17

*/public static date formatdate(string time, string format)

******dateformat f = new ******dateformat(format);

date d = f.parse(time);

return d;

} catch (exception e)

}/**

* date轉string時間

** @param time 時間字串

* @param format 格式

* @return

* @author ydl

* @date 2020-09-17

*/public static string formatdatestr(date time, string format)

******dateformat f = new ******dateformat(format);

string d = f.format(time);

return d;

} catch (exception e)

}/**

* date轉string時間

** @param time 時間字串

* @param format 格式

* @return

* @author ydl

* @date 2020-09-17

*/public static string formatdatestr(calendar time, string format)

******dateformat f = new ******dateformat(format);

string d = f.format(time.gettime());

return d;

} catch (exception e)

}/**

* 根據分鐘數計算時間

** @param min 分鐘數

* @return

* @author ydl

* @date 2020-09-17

*/public string counparktime(int min)

return time;

} /**

* 兩個時間相差距離多少天多少小時多少分多少秒

* * 時間引數 1 格式:1990-01-01 12:00:00 時間引數 2 格式:2009-01-01 12:00:00

* * @return string 返回值為:xx天xx小時xx分xx秒

*/public static mapgetdistancetime(date starttime, date endtime) else

day = diff / (24 * 60 * 60 * 1000);

hour = (diff / (60 * 60 * 1000) - day * 24);

min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);

sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);

} catch (exception e)

time.put("day", day + "天" + hour + "小時" + min + "分" + sec + "秒");// 時長

time.put("min", (day * 24 * 60) + (hour * 60) + min);// 分鐘數

return time;

}

時間工具類

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

時間工具類

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...