Java: getting current Day of the Week value(Java:获取当前星期几的值)
问题描述
目前,我正在创建一个 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:获取当前星期几的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java:获取当前星期几的值


基础教程推荐
- 从 python 访问 JVM 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 大摇大摆的枚举 2022-01-01