Java Code Examples for java.util.Calendar#MONDAY

The following examples show how to use java.util.Calendar#MONDAY . 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: SegmentedTimeline.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the milliseconds for midnight of the first Monday after
 * 1-Jan-1900, ignoring daylight savings.
 *
 * @return The milliseconds.
 *
 * @since 1.0.7
 */
public static long firstMondayAfter1900() {
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);

    // calculate midnight of first monday after 1/1/1900 relative to
    // current locale
    Calendar cal = new GregorianCalendar(z);
    cal.set(1900, 0, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DATE, 1);
    }
    //return cal.getTimeInMillis();
    // preceding code won't work with JDK 1.3
    return cal.getTime().getTime();
}
 
Example 2
Source File: TimeTool.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static DAYS valueOf(int dayValue){
	switch (dayValue) {
	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;
	case Calendar.SUNDAY:
		return SUNDAY;
	default:
		return null;
	}
}
 
Example 3
Source File: MyDateUtils.java    From spring-boot with Apache License 2.0 6 votes vote down vote up
/**
 * @param c
 * @return String
 * @Title:getWeekDay
 * @Description: 判断是星期几.
 */
public static String getWeekDay(Calendar c) {
    if (c == null) {
        return "星期一";
    }
    switch (c.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.MONDAY:
            return "星期一";
        case Calendar.TUESDAY:
            return "星期二";
        case Calendar.WEDNESDAY:
            return "星期三";
        case Calendar.THURSDAY:
            return "星期四";
        case Calendar.FRIDAY:
            return "星期五";
        case Calendar.SATURDAY:
            return "星期六";
        default:
            return "星期日";
    }
}
 
Example 4
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 5
Source File: WeekendConfigurationPage.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
private List<JCheckBox> createWeekendCheckBoxes(final GPCalendar calendar, String[] names) {
  Supplier<Integer> counter = new Supplier<Integer>() {
    @Override
    public Integer get() {
      int count = 0;
      for (int i = 1; i <= 7; i++) {
        if (calendar.getWeekDayType(i) == DayType.WEEKEND) {
          count++;
        }
      }
      return count;
    }
  };
  List<JCheckBox> result = Lists.newArrayListWithExpectedSize(7);
  int day = Calendar.MONDAY;
  for (int i = 0; i < 7; i++) {
    JCheckBox nextCheckBox = new JCheckBox();
    nextCheckBox.setSelected(calendar.getWeekDayType(day) == GPCalendar.DayType.WEEKEND);
    nextCheckBox.setAction(new CheckBoxAction(calendar, day, names[day - 1], nextCheckBox.getModel(), counter));
    result.add(nextCheckBox);
    if (++day >= 8) {
      day = 1;
    }
  }
  return result;
}
 
Example 6
Source File: Constants.java    From unitime with Apache License 2.0 6 votes vote down vote up
public static int getDayOfWeek(Date date) {
  	Calendar c = Calendar.getInstance(Locale.US);
  	c.setTime(date);
switch (c.get(Calendar.DAY_OF_WEEK)) {
case Calendar.MONDAY:
	return DAY_MON;
case Calendar.TUESDAY:
	return DAY_TUE;
case Calendar.WEDNESDAY:
	return DAY_WED;
case Calendar.THURSDAY:
	return DAY_THU;
case Calendar.FRIDAY:
	return DAY_FRI;
case Calendar.SATURDAY:
	return DAY_SAT;
case Calendar.SUNDAY:
	return DAY_SUN;
default:
	return DAY_MON;
}
  }
 
Example 7
Source File: DateUtil.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
public static Date getWeekBegin(Date date) {
    if (date == null) {
        return null;
    }
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);

    int dw = cal.get(Calendar.DAY_OF_WEEK);
    while (dw != Calendar.MONDAY) {
        cal.add(Calendar.DATE, -1);
        dw = cal.get(Calendar.DAY_OF_WEEK);
    }
    return cal.getTime();
}
 
Example 8
Source File: Bug4302966.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Calendar czechCalendar = Calendar.getInstance(new Locale("cs"));
    int firstDayOfWeek = czechCalendar.getFirstDayOfWeek();
    if (firstDayOfWeek != Calendar.MONDAY) {
        throw new RuntimeException();
    }
}
 
Example 9
Source File: LocaleTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @bug 4143951
 * Russian first day of week should be Monday. Confirmed.
 */
public void Test4143951() {
    Calendar cal = Calendar.getInstance(new Locale("ru", "", ""));
    if (cal.getFirstDayOfWeek() != Calendar.MONDAY) {
        errln("Fail: First day of week in Russia should be Monday");
    }
}
 
Example 10
Source File: WeekWeatherAdapter.java    From privacy-friendly-weather with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(WeekForecastViewHolder holder, int position) {
    Forecast f = forecastList.get(position);

    setIcon(f.getWeatherID(), holder.weather);
    holder.humidity.setText(StringFormatUtils.formatInt(f.getHumidity(), "%"));

    Calendar c = new GregorianCalendar();
    c.setTime(f.getLocalForecastTime(context));
    int day = c.get(Calendar.DAY_OF_WEEK);

    switch(day) {
        case Calendar.MONDAY:
            day = R.string.abbreviation_monday;
            break;
        case Calendar.TUESDAY:
            day = R.string.abbreviation_tuesday;
            break;
        case Calendar.WEDNESDAY:
            day = R.string.abbreviation_wednesday;
            break;
        case Calendar.THURSDAY:
            day = R.string.abbreviation_thursday;
            break;
        case Calendar.FRIDAY:
            day = R.string.abbreviation_friday;
            break;
        case Calendar.SATURDAY:
            day = R.string.abbreviation_saturday;
            break;
        case Calendar.SUNDAY:
            day = R.string.abbreviation_sunday;
            break;
        default:
            day = R.string.abbreviation_monday;
    }
    holder.day.setText(day);
    holder.temperature.setText(StringFormatUtils.formatTemperature(context, f.getTemperature()));
}
 
Example 11
Source File: Dayname.java    From tddl5 with Apache License 2.0 5 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 dayname = cal.get(Calendar.DAY_OF_WEEK);
    switch (dayname) {
        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:
            throw new FunctionException("impossbile");
    }
}
 
Example 12
Source File: DateUtilsBasic.java    From tmxeditor8 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 13
Source File: Bug4302966.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Calendar czechCalendar = Calendar.getInstance(new Locale("cs"));
    int firstDayOfWeek = czechCalendar.getFirstDayOfWeek();
    if (firstDayOfWeek != Calendar.MONDAY) {
        throw new RuntimeException();
    }
}
 
Example 14
Source File: LocaleTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @bug 4143951
 * Russian first day of week should be Monday. Confirmed.
 */
public void Test4143951() {
    Calendar cal = Calendar.getInstance(new Locale("ru", "", ""));
    if (cal.getFirstDayOfWeek() != Calendar.MONDAY) {
        errln("Fail: First day of week in Russia should be Monday");
    }
}
 
Example 15
Source File: Bug4527203.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Calendar huCalendar = Calendar.getInstance(new Locale("hu","HU"));
    int hufirstDayOfWeek = huCalendar.getFirstDayOfWeek();
    if (hufirstDayOfWeek != Calendar.MONDAY) {
        throw new RuntimeException();
    }

    Calendar ukCalendar = Calendar.getInstance(new Locale("uk","UA"));
    int ukfirstDayOfWeek = ukCalendar.getFirstDayOfWeek();
    if (ukfirstDayOfWeek != Calendar.MONDAY) {
        throw new RuntimeException();
    }

}
 
Example 16
Source File: DateUtil.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
public static Date getWeekBegin(Calendar tmp) {
    if (tmp == null) {
        return null;
    }

    Calendar ctmp =
            new GregorianCalendar(tmp.get(Calendar.YEAR), tmp.get(Calendar.MONTH), tmp.get(Calendar.DAY_OF_MONTH));

    int dw = ctmp.get(Calendar.DAY_OF_WEEK);
    while (dw != Calendar.MONDAY) {
        ctmp.add(Calendar.DATE, -1);
        dw = ctmp.get(Calendar.DAY_OF_WEEK);
    }
    return ctmp.getTime();
}
 
Example 17
Source File: TimerHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
private static ArrayList<WeekdayTimer.Day> getExecutionDays(Long timerId) throws Exception {
    ArrayList<WeekdayTimer.Day> days = new ArrayList<>();

    String[] columns = {TimerWeekdayTable.COLUMN_EXECUTION_DAY};
    Cursor cursor = DatabaseHandler.database.query(TimerWeekdayTable.TABLE_NAME, columns,
            TimerWeekdayTable.COLUMN_TIMER_ID + "=" + timerId, null, null, null, null);

    cursor.moveToFirst();

    while (!cursor.isAfterLast()) {
        switch (cursor.getInt(0)) {
            case Calendar.MONDAY:
                days.add(WeekdayTimer.Day.MONDAY);
                break;
            case Calendar.TUESDAY:
                days.add(WeekdayTimer.Day.TUESDAY);
                break;
            case Calendar.WEDNESDAY:
                days.add(WeekdayTimer.Day.WEDNESDAY);
                break;
            case Calendar.THURSDAY:
                days.add(WeekdayTimer.Day.THURSDAY);
                break;
            case Calendar.FRIDAY:
                days.add(WeekdayTimer.Day.FRIDAY);
                break;
            case Calendar.SATURDAY:
                days.add(WeekdayTimer.Day.SATURDAY);
                break;
            case Calendar.SUNDAY:
                days.add(WeekdayTimer.Day.SUNDAY);
                break;
        }
        cursor.moveToNext();
    }

    cursor.close();
    return days;
}
 
Example 18
Source File: DateUtils.java    From ToolsFinal with Apache License 2.0 4 votes vote down vote up
/**
 * 获取某天是星期几
 * @param date
 * @return
 */
public static String getMonthDayWeek(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    int year = c.get(Calendar.YEAR);    //获取年
    int month = c.get(Calendar.MONTH) + 1;   //获取月份,0表示1月份
    int day = c.get(Calendar.DAY_OF_MONTH);    //获取当前天数
    int week = c.get(Calendar.DAY_OF_WEEK);

    String weekStr = null;

    switch (week) {

        case Calendar.SUNDAY:
            weekStr = "周日";
            break;

        case Calendar.MONDAY:
            weekStr = "周一";
            break;

        case Calendar.TUESDAY:
            weekStr = "周二";
            break;

        case Calendar.WEDNESDAY:
            weekStr = "周三";
            break;

        case Calendar.THURSDAY:
            weekStr = "周四";
            break;

        case Calendar.FRIDAY:
            weekStr = "周五";
            break;

        case Calendar.SATURDAY:
            weekStr = "周六";
            break;
    }

    return month + "月" + day + "日"  + "(" + weekStr + ")";
}
 
Example 19
Source File: AddSectionsBean.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public String getMonday() {
    return daysOfWeek[Calendar.MONDAY];
}
 
Example 20
Source File: AddSectionsBean.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public String getMonday() {
    return daysOfWeek[Calendar.MONDAY];
}