本文介紹了Java:獲取當前星期幾的值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
目前,我正在創建一個 java 日程安排應用程序,我想知道如何在使用 Calendar 類獲取一周的第一天時找到一周中的當前日期.
At the moment, I'm creating a java schedule app and I was wondering how to find the current day of the week while using the Calendar class to get the first day of the week.
這是我在課堂上用來設置一周時間表的方法
Here is the method I'm using in a class in order to set up a week schedule
public static String getSunday() {
SimpleDateFormat d = new SimpleDateFormat(dayDate);
Calendar specific = cal;
specific.add(Calendar.DAY_OF_YEAR, (cal.getFirstDayOfWeek() - ??));
return d.format(specific.getTime());
}
推薦答案
可以通過Calendar.DAY_OF_WEEK
調用get()
獲取當前星期幾/p>
You can get the current day of the week by calling get()
with Calendar.DAY_OF_WEEK
public int getTodaysDayOfWeek() {
final Calendar c = Calendar.getInstance();
return c.get(Calendar.DAY_OF_WEEK);
}
另外,雖然我不確定我是否完全理解您要做什么,但對我來說它看起來很可疑.(例如 cal
是什么?)
Also, while I'm not sure I understand exactly what you're trying to do, it looks fishy to me. (What's cal
for example?)
這篇關于Java:獲取當前星期幾的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!