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


Java GregorianCalendar.equals方法代碼示例

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


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

示例1: TestFieldSet4781

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public void TestFieldSet4781() {
    try {
        GregorianCalendar g = new GregorianCalendar();
        GregorianCalendar g2 = new GregorianCalendar();
        // At this point UTC value is set, various fields are not.
        // Now set to noon.
        g2.set(HOUR, 12);
        g2.set(MINUTE, 0);
        g2.set(SECOND, 0);
        // At this point the object thinks UTC is NOT set, but fields are set.
        // The following line will result in IllegalArgumentException because
        // it thinks the YEAR is set and it is NOT.
        if (g2.equals(g)) {
            logln("Same");
        } else {
            logln("Different");
        }
    } catch (IllegalArgumentException e) {
        errln("Unexpected exception seen: " + e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:CalendarTest.java

示例2: Test4966499

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * 4973919: Inconsistent GregorianCalendar hashCode before and after serialization
 */
public void Test4966499() throws Exception {
    GregorianCalendar date1 = new GregorianCalendar(2004, JANUARY, 7);

    // Serialize date1
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(date1);

    byte[] buffer = baos.toByteArray();

    // Deserialize it
    ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
    ObjectInputStream ois = new ObjectInputStream(bais);
    GregorianCalendar date2 = (GregorianCalendar) ois.readObject();

    if (!date1.equals(date2)) {
        errln("date1.equals(date2) != true");
    }
    if (date1.hashCode() != date2.hashCode()) {
        errln("inconsistent hashCode() value (before=0x"
                + Integer.toHexString(date1.hashCode())
                + ", after=0x" + Integer.toHexString(date2.hashCode()) + ")");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:CalendarRegression.java

示例3: Test4035301

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public void Test4035301() {
    GregorianCalendar c = new GregorianCalendar(98, 8, 7);
    GregorianCalendar d = new GregorianCalendar(98, 8, 7);
    if (c.after(d)
            || c.after(c)
            || c.before(d)
            || c.before(c)
            || !c.equals(c)
            || !c.equals(d)) {
        errln("Fail");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:CalendarRegression.java

示例4: Test4092362

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public void Test4092362() {
    GregorianCalendar cal1 = new GregorianCalendar(1997, 10, 11, 10, 20, 40);
    /*cal1.set( Calendar.YEAR, 1997 );
    cal1.set( Calendar.MONTH, 10 );
    cal1.set( Calendar.DATE, 11 );
    cal1.set( Calendar.HOUR, 10 );
    cal1.set( Calendar.MINUTE, 20 );
    cal1.set( Calendar.SECOND, 40 ); */

    logln(" Cal1 = " + cal1.getTime().getTime());
    logln(" Cal1 time in ms = " + cal1.get(MILLISECOND));
    for (int k = 0; k < 100; k++);

    GregorianCalendar cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40);
    /*cal2.set( Calendar.YEAR, 1997 );
    cal2.set( Calendar.MONTH, 10 );
    cal2.set( Calendar.DATE, 11 );
    cal2.set( Calendar.HOUR, 10 );
    cal2.set( Calendar.MINUTE, 20 );
    cal2.set( Calendar.SECOND, 40 ); */

    logln(" Cal2 = " + cal2.getTime().getTime());
    logln(" Cal2 time in ms = " + cal2.get(MILLISECOND));
    if (!cal1.equals(cal2)) {
        errln("Fail: Milliseconds randomized");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:CalendarRegression.java

示例5: Test4141665

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * GregorianCalendar.equals() ignores cutover date
 */
public void Test4141665() {
    GregorianCalendar cal = new GregorianCalendar();
    GregorianCalendar cal2 = (GregorianCalendar) cal.clone();
    Date cut = cal.getGregorianChange();
    Date cut2 = new Date(cut.getTime() + 100 * 24 * 60 * 60 * 1000L); // 100 days later
    if (!cal.equals(cal2)) {
        errln("Cloned GregorianCalendars not equal");
    }
    cal2.setGregorianChange(cut2);
    if (cal.equals(cal2)) {
        errln("GregorianCalendar.equals() ignores cutover");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:CalendarRegression.java


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