當前位置: 首頁>>代碼示例>>Java>>正文


Java Calendar.equals方法代碼示例

本文整理匯總了Java中java.util.Calendar.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.equals方法的具體用法?Java Calendar.equals怎麽用?Java Calendar.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Calendar的用法示例。


在下文中一共展示了Calendar.equals方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dispatchOnRangeSelected

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Dispatch a range of days to a listener, if set. First day must be before last Day.
 *
 * @param firstDay first day enclosing a range
 * @param lastDay  last day enclosing a range
 */
protected void dispatchOnRangeSelected(final CalendarDay firstDay, final CalendarDay lastDay) {
    final OnRangeSelectedListener listener = rangeListener;
    final List<CalendarDay> days = new ArrayList<>();

    final Calendar counter = Calendar.getInstance();
    counter.setTime(firstDay.getDate());  //  start from the first day and increment

    final Calendar end = Calendar.getInstance();
    end.setTime(lastDay.getDate());  //  for comparison

    while (counter.before(end) || counter.equals(end)) {
        final CalendarDay current = CalendarDay.from(counter);
        adapter.setDateSelected(current, true);
        days.add(current);
        counter.add(Calendar.DATE, 1);
    }

    if (listener != null) {
        listener.onRangeSelected(MaterialCalendarView.this, days);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:MaterialCalendarView.java

示例2: dispatchOnRangeSelected

import java.util.Calendar; //導入方法依賴的package包/類
/**
     * Dispatch a range of days to a listener, if set. First day must be before last Day.
     *
     * @param firstDay first day enclosing a range
     * @param lastDay  last day enclosing a range
     */
    protected void dispatchOnRangeSelected(final CalendarDay firstDay, final CalendarDay lastDay) {
        final OnRangeSelectedListener listener = rangeListener;
        final List<CalendarDay> days = new ArrayList<>();

        final Calendar counter = Calendar.getInstance();
        counter.setTime(firstDay.getDate());  //  start from the first day and increment

        final Calendar end = Calendar.getInstance();
        end.setTime(lastDay.getDate());  //  for comparison

        while (counter.before(end) || counter.equals(end)) {
            final CalendarDay current = CalendarDay.from(counter);
//            adapter.setDateSelected(current, true);
            days.add(current);
            counter.add(Calendar.DATE, 1);
        }

        Collections.sort(days, new CalendarDayComparator());
        adapter.setDateRangeSelected(days);

        if (listener != null) {
            listener.onRangeSelected(CalendarView2.this, days);
        }
    }
 
開發者ID:ptrstovka,項目名稱:calendarview2,代碼行數:31,代碼來源:CalendarView2.java

示例3: isThisWeek

import java.util.Calendar; //導入方法依賴的package包/類
private static boolean isThisWeek (Calendar scheduleDay, Calendar until) {
    Calendar weekStart = Calendar.getInstance();
    stripTime(weekStart);
    weekStart.set(Calendar.DAY_OF_WEEK, weekStart.getFirstDayOfWeek());
    Calendar weekEnd = Calendar.getInstance();
    weekEnd.setTime(weekStart.getTime());
    weekEnd.add(Calendar.DATE, 7);
    
    return scheduleDay.equals(weekStart) && until.equals(weekEnd);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:SchedulingPickerImpl.java

示例4: isNextWeek

import java.util.Calendar; //導入方法依賴的package包/類
private static boolean isNextWeek (Calendar scheduleDay, Calendar until) {
    Calendar weekStart = Calendar.getInstance();
    stripTime(weekStart);
    weekStart.set(Calendar.DAY_OF_WEEK, weekStart.getFirstDayOfWeek());
    weekStart.add(Calendar.DATE, 7);
    Calendar weekEnd = Calendar.getInstance();
    weekEnd.setTime(weekStart.getTime());
    weekEnd.add(Calendar.DATE, 7);
    
    return scheduleDay.equals(weekStart) && until.equals(weekEnd);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:SchedulingPickerImpl.java

示例5: formatDateDiff

import java.util.Calendar; //導入方法依賴的package包/類
public static String formatDateDiff(Calendar fromDate, Calendar toDate) {
	boolean future = false;
	if (toDate.equals(fromDate)) {
		return I18N.tr("now");
	}
	if (toDate.after(fromDate)) {
		future = true;
	}
	StringBuilder sb = new StringBuilder();
	int[] types = { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND };
	String[] names = {
		I18N.tr("year"), I18N.tr("years"),
		I18N.tr("month"), I18N.tr("months"),
		I18N.tr("day"), I18N.tr("days"),
		I18N.tr("hour"), I18N.tr("hours"),
		I18N.tr("minute"), I18N.tr("minutes"),
		I18N.tr("second"), I18N.tr("seconds")
	};
	int accuracy = 0;
	for (int i = 0; i < types.length; i++) {
		if (accuracy > 2) {
			break;
		}
		int diff = dateDiff(types[i], fromDate, toDate, future);
		if (diff > 0) {
			accuracy++;
			sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
		}
	}
	if (sb.length() == 0) {
		return "now";
	}
	return sb.toString().trim();
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:35,代碼來源:DateUtils.java

示例6: skipCompare

import java.util.Calendar; //導入方法依賴的package包/類
@Override
protected boolean skipCompare(final String columnName, final Object expectedValue, final Object actualValue) {
    final boolean result;
    if (actualValue instanceof Timestamp && TODAY.equals(expectedValue)) {
        final Calendar actualCalendar = Calendar.getInstance();
        final Calendar expectedCalendar = (Calendar) actualCalendar.clone();
        actualCalendar.setTimeInMillis(((Timestamp) actualValue).getTime());
        clearTime(actualCalendar);
        clearTime(expectedCalendar);
        result = actualCalendar.equals(expectedCalendar);
    } else {
        result = false;
    }
    return result;
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:16,代碼來源:AbstractDBUnitUtil.java

示例7: getScheduledTime

import java.util.Calendar; //導入方法依賴的package包/類
public static Date getScheduledTime() {

        Calendar startTime = Calendar.getInstance();
        Calendar now = Calendar.getInstance();
        startTime.set(Calendar.HOUR_OF_DAY, 0);
        startTime.set(Calendar.MINUTE, 0);
        startTime.set(Calendar.SECOND, 0);
        startTime.set(Calendar.MILLISECOND, 0);

        if (startTime.before(now) || startTime.equals(now)) {
            startTime.add(Calendar.DATE, 1);
        }

        return startTime.getTime();
    }
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:16,代碼來源:Tools.java

示例8: days

import java.util.Calendar; //導入方法依賴的package包/類
public List<CalendarDay> days() {
    List<CalendarDay> calendarDays = new ArrayList<>();
    Calendar from = Calendar.getInstance();
    this.from.copyTo(from);
    Calendar to = Calendar.getInstance();
    this.to.copyTo(to);

    while (from.before(to) || from.equals(to)) {
        calendarDays.add(CalendarDay.from(from));
        from.add(Calendar.DAY_OF_YEAR, 1);
    }

    return calendarDays;
}
 
開發者ID:ptrstovka,項目名稱:calendarview2,代碼行數:15,代碼來源:Range.java

示例9: Test4080631

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 4080631: Calendar.hashCode is amazingly bad
 */
public void Test4080631() {
    Calendar cal = Calendar.getInstance();
    int h1 = cal.hashCode();
    cal.add(SECOND, +1);
    int h2 = cal.hashCode();
    Calendar cal2 = (Calendar) cal.clone();
    cal.add(MILLISECOND, +1);
    int h3 = cal.hashCode();
    logln("hash code: h1=" + h1 + ", h2=" + h2 + ", h3=" + h3);
    if (h1 == h2 || h1 == h3 || h2 == h3) {
        errln("hash code is poor: hashCode=" + h1);
    }
    h2 = cal2.hashCode();
    cal.add(MILLISECOND, -1);
    int h4 = cal.hashCode();
    logln("hash code: h2=" + h2 + ", h4=" + h4);
    if (cal.equals(cal2) && h2 != h4) {
        errln("broken hash code: h2=" + h2 + ", h4=" + h4);
    }
    int x = cal.getFirstDayOfWeek() + 3;
    if (x > SATURDAY) {
        x -= 7;
    }
    cal.setFirstDayOfWeek(x);
    int h5 = cal.hashCode();
    logln("hash code: h4=" + h4 + ", h5=" + h5);
    if (h4 == h5) {
        errln("has code is poor with first day of week param: hashCode=" + h4);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:CalendarRegression.java

示例10: isAnotherDaySelected

import java.util.Calendar; //導入方法依賴的package包/類
private boolean isAnotherDaySelected(SelectedDay selectedDay, Calendar day) {
    return selectedDay != null && !day.equals(selectedDay.getCalendar())
            && isCurrentMonthDay(day) && isActiveDay(day);
}
 
開發者ID:Applandeo,項目名稱:Material-Calendar-View,代碼行數:5,代碼來源:DayRowClickListener.java

示例11: Test4413980

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Test whether Calendar can be serialized/deserialized correctly
 * even if invalid/customized TimeZone is used.
 */
public void Test4413980() {
    TimeZone savedTimeZone = TimeZone.getDefault();
    try {
        boolean pass = true;
        String[] IDs = new String[]{"Undefined", "PST", "US/Pacific",
            "GMT+3:00", "GMT-01:30"};
        for (int i = 0; i < IDs.length; i++) {
            TimeZone tz = TimeZone.getTimeZone(IDs[i]);
            TimeZone.setDefault(tz);

            Calendar c = Calendar.getInstance();

            // serialize
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ObjectOutputStream s = new ObjectOutputStream(out);
            s.writeObject(c);
            s.flush();

            // deserialize
            ObjectInputStream t = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));

            if (!c.equals(t.readObject())) {
                pass = false;
                logln("Calendar instance which uses TimeZone <"
                        + IDs[i] + "> is incorrectly serialized/deserialized.");
            } else {
                logln("Calendar instance which uses TimeZone <"
                        + IDs[i] + "> is correctly serialized/deserialized.");
            }
        }
        if (!pass) {
            errln("Fail: Calendar serialization/equality bug");
        }
    } catch (IOException | ClassNotFoundException e) {
        errln("Fail: " + e);
        e.printStackTrace();
    } finally {
        TimeZone.setDefault(savedTimeZone);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:45,代碼來源:CalendarRegression.java

示例12: setCurrentMonthDayColors

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * This method is used to set a color of texts, font types and backgrounds of TextView objects
 * in a current visible month. Visible day labels from previous and forward months are set using
 * setDayColors() method. It also checks if a day number is a day number of today and set it
 * a different color and bold face type.
 *
 * @param day                A calendar instance representing day date
 * @param today              A calendar instance representing today date
 * @param dayLabel           TextView containing a day number
 * @param calendarProperties A resource of a color used to mark today day
 */
public static void setCurrentMonthDayColors(Calendar day, Calendar today, TextView dayLabel,
                                            CalendarProperties calendarProperties) {
    if (today.equals(day)) {
        setDayColors(dayLabel, calendarProperties.getTodayLabelColor(), Typeface.BOLD,
                R.drawable.background_transparent);
    } else {
        setDayColors(dayLabel, calendarProperties.getDaysLabelsColor(), Typeface.NORMAL,
                R.drawable.background_transparent);
    }
}
 
開發者ID:Applandeo,項目名稱:Material-Calendar-View,代碼行數:22,代碼來源:DayColorsUtils.java


注:本文中的java.util.Calendar.equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。