
很多朋友都想知道java獲取本周日期?下面就一起來了解一下吧~
//獲得本周一日期 ????????Date?timesWeekmorning?=?getTimesWeekmorning(); ????????String?format1?=?format.format(timesWeekmorning);
????????//獲得本周日日期 ????????Date?timesWeeknight?=?getTimesWeeknight(); ????????String?format2?=format.format(timesWeeknight);
????????//?獲得本月第一天日期 ????????Date?timesMonthmorning?=?getTimesMonthmorning(); ????????String?format3?=format.format(timesMonthmorning);
????????//?獲得本月最后一天日期 ????????Date?timesMonthnight?=?getTimesMonthnight(); ????????String?format4?=format.format(timesMonthnight);

//?獲得本周一0點時間
????public?static?Date?getTimesWeekmorning()?{
????????Calendar?cal?=?Calendar.getInstance();
????????cal.set(cal.get(Calendar.YEAR),?cal.get(Calendar.MONDAY),?cal.get(Calendar.DAY_OF_MONTH),?0,?0,?0);
????????cal.set(Calendar.DAY_OF_WEEK,?Calendar.MONDAY);
????????return?cal.getTime();
????}????//?獲得本周日24點時間
????public?static?Date?getTimesWeeknight()?{
????????Calendar?cal?=?Calendar.getInstance();
????????cal.setTime(getTimesWeekmorning());
????????cal.add(Calendar.DAY_OF_WEEK,?7);
????????return?cal.getTime();
????}????//?獲得本月第一天0點時間
????public?static?Date?getTimesMonthmorning()?{
????????Calendar?cal?=?Calendar.getInstance();
????????cal.set(cal.get(Calendar.YEAR),?cal.get(Calendar.MONDAY),?cal.get(Calendar.DAY_OF_MONTH),?0,?0,?0);
????????cal.set(Calendar.DAY_OF_MONTH,?cal.getActualMinimum(Calendar.DAY_OF_MONTH));
????????return?cal.getTime();
????}????//?獲得本月最后一天24點時間
????public?static?Date?getTimesMonthnight()?{
????????Calendar?cal?=?Calendar.getInstance();
????????cal.set(cal.get(Calendar.YEAR),?cal.get(Calendar.MONDAY),?cal.get(Calendar.DAY_OF_MONTH),?0,?0,?0);
????????cal.set(Calendar.DAY_OF_MONTH,?cal.getActualMaximum(Calendar.DAY_OF_MONTH));
????????cal.set(Calendar.HOUR_OF_DAY,?24);
????????return?cal.getTime();
????}以上就是小編今天的分享,希望能夠幫到大家。
