本文介紹了試圖獲取本周星期一的日期的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我已經實現了一種方法來獲取本周星期一的日期,并且我已將星期一指定為一周的第一天.
I have implemented a method to get the date of the Monday in the current week, and I have assigned Monday to be the first day of the week.
但是,無論我做什么,它都會返回 Sun Mar 24 15:03:07 GMT 2013.我看不出這里有什么問題.有人能幫忙嗎?
But, no matter what I do, it returns Sun Mar 24 15:03:07 GMT 2013. I can't see what the issue is here. Anybody able to help?
public static Date getFirstDayOfWeekDate()
{
Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(2);
cal.set(Calendar.DAY_OF_WEEK,
cal.getActualMinimum(Calendar.DAY_OF_WEEK));
Date firstDayOfTheWeek = cal.getTime();
return firstDayOfTheWeek;
}
推薦答案
試試這個:
public static Date getFirstDayOfWeekDate() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK,
cal.getActualMinimum(Calendar.DAY_OF_WEEK));
Date now = new Date();
cal.setTime(now);
int week = cal.get(Calendar.DAY_OF_WEEK);
return new Date(now.getTime() - 24 * 60 * 60 * 1000 * (week - 1));
}
這篇關于試圖獲取本周星期一的日期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!