Java Code Examples for java.util.Calendar#SUNDAY

The following examples show how to use java.util.Calendar#SUNDAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateHelper.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 获取星期几
 *
 * @param date
 * @param format
 * @return 周日 周一 周二 周三 周四 周五 周六
 * @throws ParseException
 */
public static String getWeekDay(String date, String format) throws ParseException {
    Calendar c = gc(date, format);
    if (c != null) {
        int weekDay = c.get(Calendar.DAY_OF_WEEK);
        switch (weekDay) {
            case Calendar.SUNDAY:
                return "周日";
            case Calendar.MONDAY:
                return "周一";
            case Calendar.TUESDAY:
                return "周二";
            case Calendar.WEDNESDAY:
                return "周三";
            case Calendar.THURSDAY:
                return "周四";
            case Calendar.FRIDAY:
                return "周五";
            case Calendar.SATURDAY:
                return "周六";
        }
    }
    return "";

}
 
Example 2
Source File: OHDateUtils.java    From oneHookLibraryAndroid with Apache License 2.0 6 votes vote down vote up
public static int getTodayWeekdayNormalized() {
    final Calendar calendar = Calendar.getInstance();
    final int weekday = calendar.get(Calendar.DAY_OF_WEEK);
    switch (weekday) {
        case Calendar.SUNDAY:
            return 0;
        case Calendar.MONDAY:
            return 1;
        case Calendar.TUESDAY:
            return 2;
        case Calendar.WEDNESDAY:
            return 3;
        case Calendar.THURSDAY:
            return 4;
        case Calendar.FRIDAY:
            return 5;
        case Calendar.SATURDAY:
            return 6;
        default:
            return 0;
    }
}
 
Example 3
Source File: Event.java    From unitime with Apache License 2.0 6 votes vote down vote up
public String getDays(String[] dayNames, String[] shortDyNames) {
    int nrDays = 0;
    int dayCode = 0;
    for (Meeting meeting : getMeetings()) {
        int dc = 0;
        switch (meeting.getDayOfWeek()) {
           case Calendar.MONDAY    : dc = Constants.DAY_CODES[Constants.DAY_MON]; break;
           case Calendar.TUESDAY   : dc = Constants.DAY_CODES[Constants.DAY_TUE]; break;
           case Calendar.WEDNESDAY : dc = Constants.DAY_CODES[Constants.DAY_WED]; break;
           case Calendar.THURSDAY  : dc = Constants.DAY_CODES[Constants.DAY_THU]; break;
           case Calendar.FRIDAY    : dc = Constants.DAY_CODES[Constants.DAY_FRI]; break;
           case Calendar.SATURDAY  : dc = Constants.DAY_CODES[Constants.DAY_SAT]; break;
           case Calendar.SUNDAY    : dc = Constants.DAY_CODES[Constants.DAY_SUN]; break;
        }
        if ((dayCode & dc)==0) nrDays++;
        dayCode |= dc;
    }
       String ret = "";
    for (int i=0;i<Constants.DAY_CODES.length;i++) {
        if ((dayCode & Constants.DAY_CODES[i])!=0)
            ret += (nrDays==1?dayNames:shortDyNames)[i];
    }
       return ret;
}
 
Example 4
Source File: Weekday.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
@Override
public Object compute(Object[] args, ExecutionContext ec) {
    for (Object arg : args) {
        if (ExecUtils.isNull(arg)) {
            return null;
        }
    }

    java.sql.Timestamp timestamp = DataType.TimestampType.convertFrom(args[0]);
    Calendar cal = Calendar.getInstance();
    cal.setTime(timestamp);

    int week = cal.get(Calendar.DAY_OF_WEEK);
    if (week == Calendar.SUNDAY) {
        return 6;
    } else {
        return week - 2;
    }
}
 
Example 5
Source File: DateTimeTextProvider.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private static int toWeekDay(int calWeekDay) {
    if (calWeekDay == Calendar.SUNDAY) {
        return 7;
    } else {
        return calWeekDay - 1;
    }
}
 
Example 6
Source File: DateTimeTextProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
Example 7
Source File: TimeMessage.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static byte dayOfWeekToRawBytes(Calendar cal) {
    int calValue = cal.get(Calendar.DAY_OF_WEEK);
    switch (calValue) {
        case Calendar.SUNDAY:
            return 7;
        default:
            return (byte) (calValue - 1);
    }
}
 
Example 8
Source File: DateUtils.java    From litchi with Apache License 2.0 5 votes vote down vote up
public static long getWeekMonday0AM(long time) {
	Calendar calendar = getCalendar();
	calendar.setTimeInMillis(time);
	if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
		calendar.add(Calendar.DAY_OF_WEEK, -1);
	}
	calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.MILLISECOND, 0);
	return calendar.getTimeInMillis();
}
 
Example 9
Source File: SimpleTimeZoneTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testDstNewYork2014_2ndSundayMarch_1stSundayNovember_StandardTime() {
    TimeZone timeZone = new SimpleTimeZone(NEW_YORK_RAW_OFFSET, "EST",
            Calendar.MARCH, 2, Calendar.SUNDAY, 7200000, SimpleTimeZone.STANDARD_TIME,
            Calendar.NOVEMBER, 1, Calendar.SUNDAY, 3600000, SimpleTimeZone.STANDARD_TIME,
            3600000);

    checkDstNewYork2014(timeZone);
}
 
Example 10
Source File: DateTimeTextProvider.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
Example 11
Source File: DateTimeTextProvider.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static int toWeekDay(int calWeekDay) {
    if (calWeekDay == Calendar.SUNDAY) {
        return 7;
    } else {
        return calWeekDay - 1;
    }
}
 
Example 12
Source File: DateTimeTextProvider.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int toWeekDay(int calWeekDay) {
    if (calWeekDay == Calendar.SUNDAY) {
        return 7;
    } else {
        return calWeekDay - 1;
    }
}
 
Example 13
Source File: DateTimeTextProvider.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private static int toWeekDay(int calWeekDay) {
    if (calWeekDay == Calendar.SUNDAY) {
        return 7;
    } else {
        return calWeekDay - 1;
    }
}
 
Example 14
Source File: DatePickerDialog.java    From AlarmOn with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
public void setFirstDayOfWeek(int startOfWeek) {
    if (startOfWeek < Calendar.SUNDAY || startOfWeek > Calendar.SATURDAY) {
        throw new IllegalArgumentException("Value must be between Calendar.SUNDAY and " +
                "Calendar.SATURDAY");
    }
    mWeekStart = startOfWeek;
    if (mDayPickerView != null) {
        mDayPickerView.onChange();
    }
}
 
Example 15
Source File: DateUtil.java    From AlipayWechatPlatform with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 根据日期,返回其星期数,周一为1,周日为7
 * @param date
 * @return
 */
public static int getWeekDay(Date date) {
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(date);
	int w = calendar.get(Calendar.DAY_OF_WEEK);
	int ret;
	if (w == Calendar.SUNDAY)
		ret = 7;
	else
		ret = w - 1;
	return ret;
}
 
Example 16
Source File: DateOperation.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 判断是否周末
 * @param recordDate
 * @return
 */
public boolean isWeekend(Date date) {
	Calendar cal = Calendar.getInstance();
    cal.setTime( date );
    if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
       return true;
    }
	return false;
}
 
Example 17
Source File: CalendarUtil.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
* Get the day of the week
  *
  * @param useLocale return locale specific day of week
* e.g. <code>SUNDAY = 1, MONDAY = 2, ...</code> in the U.S.,
*		 <code>MONDAY = 1, TUESDAY = 2, ...</code> in France. 
* @return the day of the week.
*/
public int getDay_Of_Week( boolean useLocale ) 
{
	int dayofweek = m_calendar.get(Calendar.DAY_OF_WEEK);
	if ( useLocale )
	{
		if ( dayofweek >= m_calendar.getFirstDayOfWeek() )
			dayofweek = dayofweek - (m_calendar.getFirstDayOfWeek()-Calendar.SUNDAY);
		else
			dayofweek = dayofweek + Calendar.SATURDAY - (m_calendar.getFirstDayOfWeek()-Calendar.SUNDAY);
	}
	return dayofweek;

}
 
Example 18
Source File: AlarmTest.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void alarm_RingsAt_BackwardQueueingRecurringDays() {
    Calendar cal = new GregorianCalendar();
    int D_C = cal.get(Calendar.DAY_OF_WEEK);

    for (int h = 0; h < 24; h++) {
        for (int m = 0; m < 60; m++) {
            Alarm a = Alarm.builder().hour(h).minutes(m).build();
            for (int D = Calendar.SATURDAY; D >= Calendar.SUNDAY; D--) {
                out.println("Testing (h, m, d) = ("+h+", "+m+", "+ (D-1) +")");
                int hC = cal.get(HOUR_OF_DAY); // Current hour
                int mC = cal.get(MINUTE);      // Current minute
                a.setRecurring(D - 1, true);

                int days = 0;

                if (h > hC || (h == hC && m > mC)) {
                    if (D < D_C) {
                        days = Calendar.SATURDAY - D_C + D;
                    } else if (D == D_C) {
                        days = 0; // upcoming on the same day
                    } else {
                        days = D - D_C;
                    }
                } else if (h <= hC) {
                    if (D < D_C) {
                        days = Calendar.SATURDAY - D_C + D - 1;
                    } else if (D == D_C) {
                        days = 0;
                    } else {
                        days = D - D_C - 1;
                    }
                }
                
                calculateRingTimeAndTest(h, m, days, cal, a.ringsAt());
            }
        }
    }
}
 
Example 19
Source File: TimeWindowModel.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
protected String getCalendarAbbrFor(int day) {
    switch (day) {
        case Calendar.MONDAY: return "Mo";
        case Calendar.TUESDAY: return "Tu";
        case Calendar.WEDNESDAY: return "We";
        case Calendar.THURSDAY: return "Th";
        case Calendar.FRIDAY: return "Fr";

        default:
        case Calendar.SUNDAY: return "Su";
    }
}
 
Example 20
Source File: AddSectionsBean.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public String getSunday() {
    return daysOfWeek[Calendar.SUNDAY];
}