Java Code Examples for java.util.Calendar.roll()

The following are Jave code examples for showing how to use roll() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: boohee_v5.6   File: DietDatePicker.java   View Source Code Vote up 7 votes
public View getItem(int index, View cachedView, ViewGroup parent) {
    int day = index - 30;
    Calendar newCalendar = (Calendar) DietDatePicker.this.calendar.clone();
    newCalendar.roll(6, day);
    View view = super.getItem(index, cachedView, parent);
    ((TextView) view.findViewById(R.id.weekday)).setText(new SimpleDateFormat("EEE")
            .format(newCalendar.getTime()));
    TextView monthday = (TextView) view.findViewById(R.id.monthday);
    if (day == 0) {
        monthday.setText(DateHelper.format(newCalendar.getTime()) + SocializeConstants
                .OP_OPEN_PAREN + DietDatePicker.this.ctx.getString(R.string.a9h) +
                SocializeConstants.OP_CLOSE_PAREN);
        monthday.setTextColor(-16776976);
    } else {
        monthday.setText(DateHelper.format(newCalendar.getTime()));
        monthday.setTextColor(-15658735);
    }
    return view;
}
 
Example 2
Project: android-lite-utils   File: DateUtils.java   View Source Code Vote up 7 votes
/**
 * 使指定日期向前走一天,变成“明天”的日期
 *
 * @param cal 处理日期
 */
public void forward(Calendar cal) {
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH);//0到11
    int day = cal.get(Calendar.DAY_OF_MONTH);
    int days = getDaysOfMonth(year, month + 1);
    if (day == days) {//如果是本月最后一天,还要判断年份是不是要向前滚
        if (month == 11) {//如果是12月份,年份要向前滚
            cal.roll(Calendar.YEAR, true);
            cal.set(Calendar.MONTH, 0);//月份,第一月是0
            cal.set(Calendar.DAY_OF_MONTH, 1);
        } else {//如果不是12月份
            cal.roll(Calendar.MONTH, true);
            cal.set(Calendar.DAY_OF_MONTH, 1);
        }
    } else {
        cal.roll(Calendar.DAY_OF_MONTH, 1);//如果是月内,直接天数加1
    }
}
 
Example 3
Project: amap   File: MIP_CalendarUtil2.java   View Source Code Vote up 6 votes
public String getPreviousMonthEnd()
{
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, -1);// 减一个月
    lastDate.set(Calendar.DATE, 1);// 把日期设置为当月第一天
    lastDate.roll(Calendar.DATE, -1);// 日期回滚一天,也就是本月最后一天
    str = sdf.format(lastDate.getTime());
    return str;
}
 
Example 4
Project: mastering-junit5   File: Library.java   View Source Code Vote up 6 votes
public List<Book> findBooks(final Date from, final Date to) {
    Calendar end = Calendar.getInstance();
    end.setTime(to);
    end.roll(Calendar.YEAR, 1);

    return store.stream().filter(book -> {
        return from.before(book.getPublished())
                && end.getTime().after(book.getPublished());
    }).sorted(Comparator.comparing(Book::getPublished).reversed())
            .collect(Collectors.toList());
}
 
Example 5
Project: MainCalendar   File: DateUtil.java   View Source Code Vote up 6 votes
/**
 * 获取指定年月的天数
 * @param year 指定公历年
 * @param month 指定公历月份
 * @return 该年月的天数
 */
public static int getMonthDays(int year, int month) {
    Calendar tmpCalendar = Calendar.getInstance();
    tmpCalendar.set(Calendar.YEAR, year);
    tmpCalendar.set(Calendar.MONTH, month);
    tmpCalendar.set(Calendar.DATE, 1);
    tmpCalendar.roll(Calendar.DATE, -1);

    return tmpCalendar.get(Calendar.DATE);
}
 
Example 6
Project: XinFramework   File: DateUtil.java   View Source Code Vote up 6 votes
/**
 * 获取当月的 天数
 */
public static int getCurrentMonthDay() {

    Calendar a = Calendar.getInstance();
    a.set(Calendar.DATE,
          1);
    a.roll(Calendar.DATE,
           -1);
    int maxDate = a.get(Calendar.DATE);
    return maxDate;
}
 
Example 7
Project: wall.e   File: DateKit.java   View Source Code Vote up 6 votes
/**
 * 得到指定月的天数
 * */
public static int getMonthLastDay(int year, int month)
{
	Calendar a = Calendar.getInstance();
	a.set(Calendar.YEAR, year);
	a.set(Calendar.MONTH, month - 1);
	a.set(Calendar.DATE, 1);//把日期设置为当月第一天
	a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
	int maxDate = a.get(Calendar.DATE);
	return maxDate;
}
 
Example 8
Project: xlight_android_native   File: DateUtil.java   View Source Code Vote up 6 votes
public static String getNextMonthEnd() {
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, 1);// 加一个月
    lastDate.set(Calendar.DATE, 1);// 把日期设置为当月第一天
    lastDate.roll(Calendar.DATE, -1);// 日期回滚一天,也就是本月最后一天
    str = sdf.format(lastDate.getTime());
    return str;
}
 
Example 9
Project: QN-ACTR-Release   File: GraphArrivalPanel.java   View Source Code Vote up 6 votes
/**
 * Is the method invoked to calculate the number of months in the log (Variable)
 */
private void ArrNumMonth() {
	ArrMonth = new Vector<double[]>();
	double i[];
	Calendar cal = Calendar.getInstance();
	Calendar cal2 = Calendar.getInstance();
	cal.setTimeInMillis((long) v.getValue(0));
	int y = 0;
	boolean k = false;
	int z = 0;
	while (z < v.Size()) {

		cal2.setTimeInMillis((long) v.getValue(z));
		if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)) {
			y++;
		} else {
			k = false;
			i = new double[2];
			i[0] = cal.getTimeInMillis();
			i[1] = y;
			ArrMonth.addElement(i);
			cal.roll(Calendar.MONTH, true);
			if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)) {
				y = 1;

			} else {
				y = 0;
				k = false;
			}
		}
		if (k != true) {
			z++;
		}
	}
	i = new double[2];
	i[0] = cal.getTimeInMillis();
	i[1] = y;
	ArrMonth.addElement(i);

}
 
Example 10
Project: quickhybrid-android   File: DateUtil.java   View Source Code Vote up 6 votes
/**
 * 得到指定月的天数
 */
public static int getMonthLastDay(int year, int month) {
    Calendar a = Calendar.getInstance();
    a.set(Calendar.YEAR, year);
    a.set(Calendar.MONTH, month - 1);
    a.set(Calendar.DATE, 1);// 把日期设置为当月第一天
    a.roll(Calendar.DATE, -1);// 日期回滚一天,也就是最后一天
    int maxDate = a.get(Calendar.DATE);
    return maxDate;
}
 
Example 11
Project: Neukoelln_SER316   File: TagTest.java   View Source Code Vote up 5 votes
public static CalendarDate tomorrow() {
  Calendar cal = Calendar.getInstance();
  cal.roll(Calendar.DATE, true);;
  return new CalendarDate(cal);
}
 
Example 12
Project: QN-ACTR-Release   File: GraphArrivalPanel.java   View Source Code Vote up 5 votes
/**
 * Is the method invoked to calculate the number of hours in the log (Variable)
 */
private void ArrNumHour() {
	ArrHour = new Vector<double[]>();
	double i[];
	Calendar cal = Calendar.getInstance();
	cal.setTime(new Date((long) v.getValue(0)));
	Calendar cal2 = Calendar.getInstance();
	int y = 0;
	int z = 0;
	boolean k = false;
	while (z < v.Size()) {
		cal2.setTimeInMillis((long) v.getValue(z));
		if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
				&& cal.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)
				&& cal.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY)) {
			y++;
		} else {
			k = false;
			i = new double[2];
			i[0] = cal.getTimeInMillis();
			i[1] = y;
			ArrHour.addElement(i);

			if (cal.get(Calendar.HOUR_OF_DAY) == 23) {
				cal.roll(Calendar.DAY_OF_YEAR, true);
			}
			cal.roll(Calendar.HOUR_OF_DAY, true);
			if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
					&& cal.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)
					&& cal.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY)) {
				y = 1;
			} else {
				y = 0;
				k = true;
			}
		}
		if (k != true) {
			z++;
		}

	}
	i = new double[2];
	i[0] = cal.getTimeInMillis();
	i[1] = y;
	ArrHour.addElement(i);

}
 
Example 13
Project: jmt   File: GraphArrivalPanel.java   View Source Code Vote up 5 votes
/**
 * Is the method invoked to calculate the number of minutes in the log (Variable)
 */
private void ArrNumMinute() {
	ArrMinute = new Vector<double[]>();
	double i[];
	Calendar cal = Calendar.getInstance();
	cal.setTime(new Date((long) v.getValue(0)));
	Calendar cal2 = Calendar.getInstance();
	int y = 0;
	boolean k = false;
	int z = 0;
	cal2.setTimeInMillis((long) v.getValue(z));
	while (z < v.Size()) {
		if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
				&& cal.get(Calendar.DATE) == cal2.get(Calendar.DATE) && cal.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY)
				&& cal.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE)) {
			y++;
		} else {
			k = false;
			i = new double[2];
			i[0] = cal.getTimeInMillis();
			i[1] = y;
			ArrMinute.addElement(i);
			if (cal.get(Calendar.MINUTE) == 59 && cal.get(Calendar.HOUR_OF_DAY) != 23) {
				cal.roll(Calendar.HOUR_OF_DAY, true);
			}
			if (cal.get(Calendar.MINUTE) == 59 && cal.get(Calendar.HOUR_OF_DAY) == 23) {
				cal.roll(Calendar.HOUR_OF_DAY, true);
				cal.roll(Calendar.DAY_OF_YEAR, true);
			}
			cal.roll(Calendar.MINUTE, true);
			if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
					&& cal.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)
					&& cal.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY) && cal.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE)) {
				y = 1;
			} else {
				y = 0;
				k = true;
			}
		}
		if (k != true) {
			z++;
			if (z < v.Size()) {
				cal2.setTimeInMillis((long) v.getValue(z));
			}
		}
	}
	i = new double[2];
	i[0] = cal.getTimeInMillis();
	i[1] = y;
	ArrMinute.addElement(i);
}
 
Example 14
Project: Reinickendorf_SER316   File: CalendarDate.java   View Source Code Vote up 5 votes
public static CalendarDate yesterday() {
    Calendar cal = Calendar.getInstance();
    cal.roll(Calendar.DATE, false);
    return new CalendarDate(cal);
}
 
Example 15
Project: SER316-Ingolstadt   File: CalendarDate.java   View Source Code Vote up 5 votes
public static CalendarDate tomorrow() {
    Calendar cal = Calendar.getInstance();
    cal.roll(Calendar.DATE, true);
    return new CalendarDate(cal);
}
 
Example 16
Project: SER316-Aachen   File: CalendarDate.java   View Source Code Vote up 5 votes
public static CalendarDate yesterday() {
    Calendar cal = Calendar.getInstance();
    cal.roll(Calendar.DATE, false);
    return new CalendarDate(cal);
}
 
Example 17
Project: Wilmersdorf_SER316   File: CalendarDate.java   View Source Code Vote up 5 votes
public static CalendarDate yesterday() {
    Calendar cal = Calendar.getInstance();
    cal.roll(Calendar.DATE, false);
    return new CalendarDate(cal);
}
 
Example 18
Project: SER316-Ingolstadt   File: CalendarDate.java   View Source Code Vote up 5 votes
public static CalendarDate yesterday() {
    Calendar cal = Calendar.getInstance();
    cal.roll(Calendar.DATE, false);
    return new CalendarDate(cal);
}
 
Example 19
Project: SER316-Munich   File: CalendarDate.java   View Source Code Vote up 5 votes
public static CalendarDate tomorrow() {
    Calendar cal = Calendar.getInstance();
    cal.roll(Calendar.DATE, true);
    return new CalendarDate(cal);
}
 
Example 20
Project: asura   File: DateUtil.java   View Source Code Vote up 4 votes
/**
 *
 * 获取指定日期所在月的最后一天
 *
 * @author zhangshaobin
 * @created 2012-11-5 下午7:04:10
 *
 * @param date
 * @return	以"年年年年-月月-日日"格式返回当指定月最后一天的日期
 */
public static Long getLastDayTimeOfMonth(final Date date) {
	final Calendar ca = Calendar.getInstance();
	ca.setTime(date);
	ca.set(Calendar.DAY_OF_MONTH, 1);
	ca.roll(Calendar.DAY_OF_MONTH, -1);
	//		return dateFormat.format(ca.getTime());
	return ca.getTime().getTime();
}