Calendar 获取周几

2018-04-19  本文已影响0人  茶瓯
public final static int SUNDAY = 1;
/**
 * Value of the {@link #DAY_OF_WEEK} field indicating
 * Monday.
 */
public final static int MONDAY = 2;

/**
 * Value of the {@link #DAY_OF_WEEK} field indicating
 * Tuesday.
 */
public final static int TUESDAY = 3;

/**
 * Value of the {@link #DAY_OF_WEEK} field indicating
 * Wednesday.
 */
public final static int WEDNESDAY = 4;

Calendar已经默认SUNDAY为1

    int o = calendar.get(Calendar.DAY_OF_WEEK);
    if (o == Calendar.SUNDAY) {
        int dayOfWeek = 7;
    } else {
        int dayOfWeek = o - 1;
    }

//设置一周开始的计算方式
calendar.setFirstDayOfWeek(Calendar.MONDAY);

上一篇 下一篇

猜你喜欢

热点阅读