日期:2014-05-20  浏览次数:20694 次

Calendar.DAy_OF_WEEK的打印
本帖最后由 u012432248 于 2013-12-03 12:09:51 编辑
public class CalendarTest
{
public static void main(String[] args)
{
GregorianCalendar d = new GregorianCalendar();
int today = d.get(Calendar.DAY_OF_MONTH);
int month = d.get(Calendar.MONTH);
d.set(Calendar.DAY_OF_MONTH, 1);
int weekday = d.get(Calendar.DAY_OF_WEEK);
System.out.println("   " + weekday); // 打印出来的是1 12月1日星期天
System.out.println("hjahah" + Calendar.DAY_OF_WEEK); 
// 打印出来的是7,d.set屏蔽掉直接打印Calendar.DAY_OF_WEEK也是7 为什么?不一样,这里的和
//上一句打印的不是同一内容,麻烦大神们给解释下.
}
}

------解决方案--------------------
GregorianCalendar d = new GregorianCalendar();
int weekday = d.get(Calendar.DAY_OF_WEEK);
System.out.println("   " + weekday);
d.set(Calendar.DAY_OF_MONTH, 1);
System.out.println("hjahah" + d.get(Calendar.DAY_OF_WEEK));

System.out.println("hjahah" + Calendar.DAY_OF_WEEK); //这样是打印Calendar的一个常量:DAY_OF_WEEK,当然是7了。
------解决方案--------------------
Calendar.DAY_OF_WEEK、、

DAY_OF_WEEK
public static final int DAY_OF_WEEKget 和 set 的字段数字,指示一个星期中的某天。该字段可取的值为 SUNDAY、MONDAY、TUESDAY、WEDNESDAY、THURSDAY、FRIDAY 和 SATURDAY。

楼主查一下API
------解决方案--------------------
楼主没有看Calendar类的实现吧,下面是一段代码:
/**
     * Field number for <code>get</code> and <code>set</code> indicating the
     * era, e.g., AD or BC in the Julian calendar. This is a calendar-specific
     * value; see subclass documentation.
     *
     * @see GregorianCalendar#AD
     * @see GregorianCalendar#BC
     */
    public final static int ERA = 0;

    /**
     * Field number for <code>get</code> and <code>set</code> indicating the
     * year. This is a calendar-specific value; see subclass documentation.
     */
    public final static int YEAR = 1;

    /**
     * Field number for <code>get</code> and <code>set</code> indicating the
     * month. This is a calendar-specific value. The first month of
     * the year in the Gregorian and Julian calendars is
     * <code>JANUARY</code> which is 0; the last depends on the number
     * of months in a year.
     *
     * @see #JANUARY
     * @see #FEBRUARY
     * @see #MARCH
     * @see #APRIL
     * @see #MAY
     * @see #JUNE
     * @see #JULY
     * @see #AUGUST
     * @see #SEPTEMBER
     * @see #OCTOBER
     * @see #NOVEMBER
     * @see #DECEMBER
     * @see #UNDECIMBER
     */
    public final static int MONTH = 2;

    /**
     * Field number for <code>get</code> and <code>set</code> indicating the
     * week number within the current year.  The first week of the year, as
     * defined by <code>getFirstDayOfWeek()</code> and