Java:获取当前星期值 [英] Java: getting current Day of the Week value

查看:126
本文介绍了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());
}


推荐答案

get()

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:获取当前星期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆