目前,我正在创建一个 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模板网!
解析 ISO 8601 字符串本地日期时间,就像在 UTC 中Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期时间,就像在 UTC 中一样)
如何将公历字符串转换为公历?How to convert Gregorian string to Gregorian Calendar?(如何将公历字符串转换为公历?)
Java:GregorianCalendar 的最大值和最小值是什么/在哪Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
1582 年 10 月 15 日之前日期的日历到日期转换.公历Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日历到日期转换
java日历setFirstDayOfWeek不起作用java Calendar setFirstDayOfWeek not working(java日历setFirstDayOfWeek不起作用)
设置和获取小时、分钟、秒的正确方法The correct way to set and get hour, minutes, sec(设置和获取小时、分钟、秒的正确方法)