java時間工具類

2021-08-28 11:44:38 字數 1162 閱讀 7164

public class dateutils 

/*** 獲取當天零時的時間

* @return

*/public static date gettodaystart(date date)

/*** 獲取當前周的第一天零時

* @return

*/public static date getcurrentweekstart(date date)

// 獲得當前日期是乙個星期的第幾天

int day = calendar.get(calendar.day_of_week);

// 根據日曆的規則,給當前日期減去星期幾與乙個星期第一天的差值

calendar.add(calendar.date, calendar.getfirstdayofweek() - day);

calendar.set(calendar.hour_of_day, 0);

calendar.set(calendar.minute, 0);

calendar.set(calendar.second, 0);

return calendar.gettime();

}public static date getlastweekstart(date date)

/***獲取當月1號零時時間

* @return

*/public static date getcurrentmonthstart(date date)

/*** 獲取上月1號零時時間

* @return

*/public static date getlastmonthstart(date date)

}

public class dateformatutils 

/*** 轉化時間為字串形式

* @param date

* @return

*/public static string format(date date)

/*** 將時間字串轉換為時間型別

* @param str

* @return

*/public static date format(string str) catch (parseexception e)

return parse;

}}

Java 時間工具類

public class datetimeutil else public static string datetostring date date else public static string timetostring date date else public static date pa...

java時間處理工具類

public class timehelper 預設當前時間 精確到秒 return 當前時間 public static string getnow 通過指定的格式獲取當前時間字串 param format 日期字串格式 return 當前時間字串 public static string get...

Java工具類 Java檔案工具類

public class fileutils 讀取檔案並作為byte返回 param file 目標檔案 return throws ioexception public static byte readfileasbytes file file throws ioexception 讀取檔案並作為...