Java Code Examples for java.util.Calendar#WEDNESDAY

The following examples show how to use java.util.Calendar#WEDNESDAY . 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: PdfLegacyExamReport.java    From unitime with Apache License 2.0 6 votes vote down vote up
public int getDaysCode(Set meetings) {
    int daysCode = 0;
    for (Iterator i=meetings.iterator();i.hasNext();) {
        Meeting meeting = (Meeting)i.next();
        Calendar date = Calendar.getInstance(Locale.US);
        date.setTime(meeting.getMeetingDate());
        switch (date.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.MONDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_MON]; break;
        case Calendar.TUESDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_TUE]; break;
        case Calendar.WEDNESDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_WED]; break;
        case Calendar.THURSDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_THU]; break;
        case Calendar.FRIDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_FRI]; break;
        case Calendar.SATURDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_SAT]; break;
        case Calendar.SUNDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_SUN]; break;
        }
    }
    return daysCode;
}
 
Example 3
Source File: AppUtils.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
public static int getDay(String day) {

        if(day.equals("Mon"))
            return Calendar.MONDAY;
        if(day.equals("Tue"))
            return Calendar.TUESDAY;
        if(day.equals("Wed"))
            return Calendar.WEDNESDAY;
        if(day.equals("Thu"))
            return Calendar.THURSDAY;
        if(day.equals("Fri"))
            return Calendar.FRIDAY;
        if(day.equals("Sat"))
            return Calendar.SATURDAY;
        if(day.equals("Sun"))
            return Calendar.SUNDAY;

        return Calendar.MONDAY;
    }
 
Example 4
Source File: MeetingCountingDuration.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected int nbrMeetings(DatePattern datePattern, int dayCode) {
	if (datePattern == null) return 0;
	Calendar cal = Calendar.getInstance(Locale.US);
	cal.setTime(datePattern.getStartDate()); cal.setLenient(true);
       String pattern = datePattern.getPattern();
       int ret = 0;
       for (int idx = 0; idx < pattern.length(); idx++) {
       	if (pattern.charAt(idx) == '1') {
       		boolean offered = false;
       		switch (cal.get(Calendar.DAY_OF_WEEK)) {
       			case Calendar.MONDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_MON]) != 0); break;
       			case Calendar.TUESDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_TUE]) != 0); break;
       			case Calendar.WEDNESDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_WED]) != 0); break;
       			case Calendar.THURSDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_THU]) != 0); break;
       			case Calendar.FRIDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_FRI]) != 0); break;
       			case Calendar.SATURDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_SAT]) != 0); break;
       			case Calendar.SUNDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_SUN]) != 0); break;
       		}
       		if (offered) ret++;
       	}
       	cal.add(Calendar.DAY_OF_YEAR, 1);
       }
       return ret;
}
 
Example 5
Source File: DatePicker.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
/**
 * remaps the days of week of gregorian Calendar to internal values
 */
private int mapDayOfWeek(int cal) {
    switch(cal) {
        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;
        case Calendar.SUNDAY:
            return 7;
        default:
            return 1; //should never happen
    }
}
 
Example 6
Source File: AbstractCalendarView.java    From holo-calendar with Apache License 2.0 6 votes vote down vote up
/**
 * Get a human readable name for this day of the week
 *
 * @param dayOfWeek between Calendar.SUNDAY and Calendar.SATURDAY
 * @param resources A resources object which can be retrieved by Context.getResources()
 * @return A name for this day of the week. MON - SUN.
 * @throws IllegalArgumentException Thrown when provided dayOfWeek is invalid
 */
protected String getNameForDay(final int dayOfWeek, final Resources resources) throws IllegalArgumentException {
    switch(dayOfWeek) {
        case Calendar.MONDAY:
            return resources.getString(R.string.lib_header_monday);
        case Calendar.TUESDAY:
            return resources.getString(R.string.lib_header_tuesday);
        case Calendar.WEDNESDAY:
            return resources.getString(R.string.lib_header_wednesday);
        case Calendar.THURSDAY:
            return resources.getString(R.string.lib_header_thursday);
        case Calendar.FRIDAY:
            return resources.getString(R.string.lib_header_friday);
        case Calendar.SATURDAY:
            return resources.getString(R.string.lib_header_saturday);
        case Calendar.SUNDAY:
            return resources.getString(R.string.lib_header_sunday);
        default:
            // unknown day
            throw new IllegalArgumentException("dayOfWeek is not valid. Pick a value between 1 and 7. " +
                    "dayOfWeek: " + dayOfWeek);
    }
}
 
Example 7
Source File: TimeProfile.java    From sample-bluetooth-le-gattserver with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a {@link Calendar} weekday value to the corresponding
 * Bluetooth weekday code.
 */
private static byte getDayOfWeekCode(int dayOfWeek) {
    switch (dayOfWeek) {
        case Calendar.MONDAY:
            return DAY_MONDAY;
        case Calendar.TUESDAY:
            return DAY_TUESDAY;
        case Calendar.WEDNESDAY:
            return DAY_WEDNESDAY;
        case Calendar.THURSDAY:
            return DAY_THURSDAY;
        case Calendar.FRIDAY:
            return DAY_FRIDAY;
        case Calendar.SATURDAY:
            return DAY_SATURDAY;
        case Calendar.SUNDAY:
            return DAY_SUNDAY;
        default:
            return DAY_UNKNOWN;
    }
}
 
Example 8
Source File: TripDetail.java    From UberClone with MIT License 6 votes vote down vote up
private String convertToDayOfWeek(int day) {
    switch(day){
        case Calendar.SUNDAY:
            return "SUNDAY";
        case Calendar.MONDAY:
            return "MONDAY";
        case Calendar.TUESDAY:
            return "TUESDAY";
        case Calendar.WEDNESDAY:
            return "WEDNESDAY";
        case Calendar.THURSDAY:
            return "THURSDAY";
        case Calendar.FRIDAY:
            return "FRIDAY";
        case Calendar.SATURDAY:
            return "SATURDAY";
        default:
            return "UNK";
    }
}
 
Example 9
Source File: Alarm.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
private static int jodaWDToJavaWD(int wd) {
    switch (wd) {
        case DateTimeConstants.MONDAY:
            return Calendar.MONDAY;
        case DateTimeConstants.TUESDAY:
            return Calendar.TUESDAY;
        case DateTimeConstants.WEDNESDAY:
            return Calendar.WEDNESDAY;
        case DateTimeConstants.THURSDAY:
            return Calendar.THURSDAY;
        case DateTimeConstants.FRIDAY:
            return Calendar.FRIDAY;
        case DateTimeConstants.SATURDAY:
            return Calendar.SATURDAY;
        case DateTimeConstants.SUNDAY:
            return Calendar.SUNDAY;
    }
    return 0;
}
 
Example 10
Source File: DateUtilsBasic.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获得数字 i 所代表的星期,所对应的短字母.
 * @param i
 *          数字
 * @return String
 * 				如果i = 1,返回 "S"(即 "SUNDAY" 的首字母);
 * 				如果i = 2,返回 "M"(即 "MONDAY" 的首字母);
 * 				...
 * 				如果i > 7 或 i < 1,返回空串"";
 */
public static String getDayName(int i) {
	String dayname = "";
	switch (i) {
	case Calendar.MONDAY:
		dayname = "M";
		break;
	case Calendar.TUESDAY:
		dayname = "T";
		break;
	case Calendar.WEDNESDAY:
		dayname = "W";
		break;
	case Calendar.THURSDAY:
		dayname = "T";
		break;
	case Calendar.FRIDAY:
		dayname = "F";
		break;
	case Calendar.SATURDAY:
		dayname = "S";
		break;
	case Calendar.SUNDAY:
		dayname = "S";
		break;
	default:
		break;
	}
	return dayname;
}
 
Example 11
Source File: WidgetUtils.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String getWeek(Context context) {
    Calendar c = Calendar.getInstance();
    int week = c.get(Calendar.DAY_OF_WEEK);
    switch (week) {
        case Calendar.SUNDAY:
            return context.getString(R.string.week_7);

        case Calendar.MONDAY:
            return context.getString(R.string.week_1);

        case Calendar.TUESDAY:
            return context.getString(R.string.week_2);

        case Calendar.WEDNESDAY:
            return context.getString(R.string.week_3);

        case Calendar.THURSDAY:
            return context.getString(R.string.week_4);

        case Calendar.FRIDAY:
            return context.getString(R.string.week_5);

        case Calendar.SATURDAY:
            return context.getString(R.string.week_6);

        default:
            return "";
    }
}
 
Example 12
Source File: Util.java    From whyline with MIT License 5 votes vote down vote up
public static String getDayOfWeekString(int dayOfWeek) {
	
	switch(dayOfWeek) {
	case Calendar.SUNDAY : return "Sunday";
	case Calendar.MONDAY : return "Monday";
	case Calendar.TUESDAY : return "Tuesday";
	case Calendar.WEDNESDAY : return "Wednesday";
	case Calendar.THURSDAY : return "Thursday";
	case Calendar.FRIDAY : return "Friday";
	case Calendar.SATURDAY : return "Saturday";
	default : return "invalid day of week";
	}

}
 
Example 13
Source File: TheHubActivity.java    From ToDay with MIT License 5 votes vote down vote up
private void generateDrawerGreeting(NavigationView view) {
    View header=view.getHeaderView(0);
    TextView greeting = (TextView) header.findViewById(R.id.ndrawer_date_greeting);
    String[] array = this.getResources().getStringArray(R.array.drawer_greeting);

    switch(Calendar.getInstance().get(Calendar.DAY_OF_WEEK)){
        case Calendar.MONDAY:
            greeting.setText(array[0]);
            break;

        case Calendar.TUESDAY:
            greeting.setText(array[1]);
            break;

        case Calendar.WEDNESDAY:
            greeting.setText(array[2]);
            break;
        case Calendar.THURSDAY:
            greeting.setText(array[3]);
            break;
        case Calendar.FRIDAY:
            greeting.setText(array[4]);
            break;
        case Calendar.SATURDAY:
            greeting.setText(array[5]);
            break;

        case Calendar.SUNDAY:
            greeting.setText(array[6]);
            break;

        default:
            greeting.setText(array[7]);
            break;

    }

}
 
Example 14
Source File: DateUtilities.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
public static int getWeekdayIndex(String weekday) {
	if (StringUtils.isBlank(weekday)) {
		return -1;
	} else {
		weekday = weekday.toLowerCase().trim();
		String[] localeWeekdays = DateFormatSymbols.getInstance().getWeekdays();
		for (int i = 0; i < localeWeekdays.length; i++) {
			if (localeWeekdays[i].toLowerCase().startsWith(weekday)) {
				return i;
			}
		}
		
		if (weekday.startsWith("so") || weekday.startsWith("su")) {
			return Calendar.SUNDAY;
		} else if (weekday.startsWith("mo")) {
			return Calendar.MONDAY;
		} else if (weekday.startsWith("di") || weekday.startsWith("tu")) {
			return Calendar.TUESDAY;
		} else if (weekday.startsWith("mi") || weekday.startsWith("we")) {
			return Calendar.WEDNESDAY;
		} else if (weekday.startsWith("do") || weekday.startsWith("th")) {
			return Calendar.THURSDAY;
		} else if (weekday.startsWith("fr")) {
			return Calendar.FRIDAY;
		} else if (weekday.startsWith("sa")) {
			return Calendar.SATURDAY;
		} else {
			return -1;
		}
	}
}
 
Example 15
Source File: TimeUtil.java    From star-zone-android with Apache License 2.0 5 votes vote down vote up
public static String getWeek(String pTime) {
    String week = "";
    Calendar c = Calendar.getInstance();
    try {
        c.setTime(yyyymmddFormate.parse(pTime));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        week = "周日";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
        week = "周一";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY) {
        week = "周二";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) {
        week = "周三";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
        week = "周四";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {
        week = "周五";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
        week = "周六";
    }
    return week;
}
 
Example 16
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 17
Source File: EventRoomAvailabilityBackend.java    From unitime with Apache License 2.0 4 votes vote down vote up
public static TreeSet<MeetingConflictInterface> generateUnavailabilityMeetings(Location location, List<Integer> dates, int startSlot, int endSlot) {
	if (location.getEventAvailability() == null || location.getEventAvailability().length() != Constants.SLOTS_PER_DAY * Constants.DAY_CODES.length) return null;

	TreeSet<MeetingConflictInterface> ret = new TreeSet<MeetingConflictInterface>();
	
	ResourceInterface resource = new ResourceInterface();
	resource.setType(ResourceType.ROOM);
	resource.setId(location.getUniqueId());
	resource.setName(location.getLabel());
	resource.setSize(location.getCapacity());
	resource.setRoomType(location.getRoomTypeLabel());
	resource.setBreakTime(location.getEffectiveBreakTime());
	resource.setMessage(location.getEventMessage());
	resource.setIgnoreRoomCheck(location.isIgnoreRoomCheck());
	resource.setDisplayName(location.getDisplayName());
	
	Calendar calendar = Calendar.getInstance();
       for (int day = 0; day < Constants.DAY_CODES.length; day++)
       	for (int startTime = 0; startTime < Constants.SLOTS_PER_DAY; ) {
       		if (location.getEventAvailability().charAt(day * Constants.SLOTS_PER_DAY + startTime) != '1') { startTime++; continue; }
       		int endTime = startTime + 1;
       		while (endTime < Constants.SLOTS_PER_DAY && location.getEventAvailability().charAt(day * Constants.SLOTS_PER_DAY + endTime) == '1') endTime++;
       		if (startTime < endSlot && startSlot < endTime) {
           		calendar.setTime(location.getSession().getEventBeginDate());
           		int dayOfYear = CalendarUtils.date2dayOfYear(location.getSession().getSessionStartYear(), calendar.getTime());
           		
           		do {
           			if (dates.contains(dayOfYear)) {
               			int dayOfWeek = -1;
               			switch (calendar.get(Calendar.DAY_OF_WEEK)) {
               			case Calendar.MONDAY: dayOfWeek = Constants.DAY_MON; break;
               			case Calendar.TUESDAY: dayOfWeek = Constants.DAY_TUE; break;
               			case Calendar.WEDNESDAY: dayOfWeek = Constants.DAY_WED; break;
               			case Calendar.THURSDAY: dayOfWeek = Constants.DAY_THU; break;
               			case Calendar.FRIDAY: dayOfWeek = Constants.DAY_FRI; break;
               			case Calendar.SATURDAY: dayOfWeek = Constants.DAY_SAT; break;
               			case Calendar.SUNDAY: dayOfWeek = Constants.DAY_SUN; break;
               			}
               			
               			if (day == dayOfWeek) {
                   			MeetingConflictInterface m = new MeetingConflictInterface();
               				m.setName(MESSAGES.unavailableEventDefaultName());
               				m.setType(EventInterface.EventType.Unavailabile);
                       		m.setStartSlot(startTime);
                       		m.setEndSlot(endTime);
                       		m.setDayOfWeek(dayOfWeek);
                       		m.setMeetingDate(calendar.getTime());
                       		m.setDayOfYear(dayOfYear);
                       		m.setLocation(resource);
                       		ret.add(m);
               			}
           			}
           			calendar.add(Calendar.DAY_OF_YEAR, 1); dayOfYear++;
           		} while (!calendar.getTime().after(location.getSession().getEventEndDate()));        			
       		}
       		startTime = endTime;
       	}
	return ret;
}
 
Example 18
Source File: InfoFragment.java    From apollo-DuerOS with Apache License 2.0 4 votes vote down vote up
public void updateTime() {
    Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH) + 1;
    int date = c.get(Calendar.DATE);
    int hours = c.get(Calendar.HOUR_OF_DAY);
    int minutes = c.get(Calendar.MINUTE);
    int week = c.get(Calendar.DAY_OF_WEEK);

    String hour;
    String minute;
    String weekDay;

    if (hours < 10) {
        hour = "0" + hours;
    } else {
        hour = "" + hours;
    }
    if (minutes < 10) {
        minute = "0" + minutes;
    } else {
        minute = "" + minutes;
    }

    switch (week) {
        case Calendar.MONDAY:
            weekDay = getString(R.string.one);
            break;
        case Calendar.TUESDAY:
            weekDay = getString(R.string.two);
            break;
        case Calendar.WEDNESDAY:
            weekDay = getString(R.string.three);
            break;
        case Calendar.THURSDAY:
            weekDay = getString(R.string.four);
            break;
        case Calendar.FRIDAY:
            weekDay = getString(R.string.five);
            break;
        case Calendar.SATURDAY:
            weekDay = getString(R.string.six);
            break;
        case Calendar.SUNDAY:
            weekDay = getString(R.string.sunday);
            break;
        default:
            weekDay = "";
            break;
    }

    mTimeText.setText(hour + ":" + minute);
    mDateText.setText(year + getString(R.string.year) + month
            + getString(R.string.month) + date + getString(R.string.day_and_week) + weekDay);
    mHandler.removeMessages(HANDLER_CODE_REFRESH_TIME);
    mHandler.sendEmptyMessageDelayed(HANDLER_CODE_REFRESH_TIME, 1000);
}
 
Example 19
Source File: InfoFragment.java    From apollo-DuerOS with Apache License 2.0 4 votes vote down vote up
public void updateTime() {
    Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH) + 1;
    int date = c.get(Calendar.DATE);
    int hours = c.get(Calendar.HOUR_OF_DAY);
    int minutes = c.get(Calendar.MINUTE);
    int week = c.get(Calendar.DAY_OF_WEEK);

    String hour;
    String minute;
    String weekDay;

    if (hours < 10) {
        hour = "0" + hours;
    } else {
        hour = "" + hours;
    }
    if (minutes < 10) {
        minute = "0" + minutes;
    } else {
        minute = "" + minutes;
    }

    String[] weeks = getResources().getStringArray(R.array.info_week);

    switch (week) {
        case Calendar.MONDAY:
            weekDay = weeks[0];
            break;
        case Calendar.TUESDAY:
            weekDay = weeks[1];
            break;
        case Calendar.WEDNESDAY:
            weekDay = weeks[2];
            break;
        case Calendar.THURSDAY:
            weekDay = weeks[3];
            break;
        case Calendar.FRIDAY:
            weekDay = weeks[4];
            break;
        case Calendar.SATURDAY:
            weekDay = weeks[5];
            break;
        case Calendar.SUNDAY:
            weekDay = weeks[6];
            break;
        default:
            weekDay = "";
            break;
    }

    mTimeText.setText(hour + ":" + minute);
    if (mShowYear) {
        mDateText.setText(year + getResources().getString(R.string.info_year)
                + month + getResources().getString(R.string.info_month)
                + date + getResources().getString(R.string.info_day));
    } else {
        mDateText.setText(month + getResources().getString(R.string.info_month)
                + date + getResources().getString(R.string.info_day));
    }
    mWeekText.setText(getResources().getString(R.string.info_week) + weekDay);
    mHandler.removeMessages(REFRESH_TIME);
    mHandler.sendEmptyMessageDelayed(REFRESH_TIME, 1000);
}
 
Example 20
Source File: DateUtils.java    From android-utils with MIT License 4 votes vote down vote up
/**
 * Returns abbreviated (3 letters) day of the week.
 *
 * @param date ISO format date
 * @return The name of the day of the week
 */
public static String getDayOfWeekAbbreviated(String date) {
    Date dateDT = parseDate(date);

    if (dateDT == null) {
        return null;
    }

    // Get current date
    Calendar c = Calendar.getInstance();
    // it is very important to
    // set the date of
    // the calendar.
    c.setTime(dateDT);
    int day = c.get(Calendar.DAY_OF_WEEK);

    String dayStr = null;

    switch (day) {

        case Calendar.SUNDAY:
            dayStr = "Sun";
            break;

        case Calendar.MONDAY:
            dayStr = "Mon";
            break;

        case Calendar.TUESDAY:
            dayStr = "Tue";
            break;

        case Calendar.WEDNESDAY:
            dayStr = "Wed";
            break;

        case Calendar.THURSDAY:
            dayStr = "Thu";
            break;

        case Calendar.FRIDAY:
            dayStr = "Fri";
            break;

        case Calendar.SATURDAY:
            dayStr = "Sat";
            break;
    }

    return dayStr;
}