問(wèn)題描述
目前,我正在創(chuàng)建一個(gè) java 日程安排應(yīng)用程序,我想知道如何在使用 Calendar 類(lèi)獲取一周的第一天時(shí)找到一周中的當(dāng)前日期.
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.
這是我在課堂上用來(lái)設(shè)置一周時(shí)間表的方法
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());
}
推薦答案
可以通過(guò)Calendar.DAY_OF_WEEK
調(diào)用get()
獲取當(dāng)前星期幾/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);
}
另外,雖然我不確定我是否完全理解您要做什么,但對(duì)我來(lái)說(shuō)它看起來(lái)很可疑.(例如 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?)
這篇關(guān)于Java:獲取當(dāng)前星期幾的值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!