java.util.GregorianCalendar.hashCode()是Java中的內置函數,該函數為此GregorianCalendar實例生成哈希碼。
用法:
public int hashCode()
參數:該函數不接受任何參數。
返回值:此函數返回一個整數值,該值表示此GregorianCalendar實例的哈希碼。
例子:
Input : Thu Jul 24 00:53:29 UTC 1997 Output : 2121703905 Input : Tue Jul 24 00:54:11 UTC 2018 Output : -909136554
下麵的程序演示了java.util.GregorianCalendar.hashCode()函數:
示例1:
// Java Program to illustrate hashCode() function
// of GregorianCalendar class
import java.io.*;
import java.util.*;
class GFG {
public static void main(String[] args) {
// Create a new calendar
GregorianCalendar c = (GregorianCalendar)
GregorianCalendar.getInstance();
// Display the current date and time
System.out.println("Current Date and Time : "
+ c.getTime());
// Display hashcode for this calendar
System.out.println("Hash Code:" + c.hashCode());
}
}
輸出:
Current Date and Time : Fri Jul 27 11:43:16 UTC 2018 Hash Code:-612105832
示例2:
// Java Program to illustrate hashCode() function
// of GregorianCalendar class
import java.io.*;
import java.util.*;
class GFG {
public static void main(String[] args) {
// Create a new calendar
GregorianCalendar c = (GregorianCalendar)
GregorianCalendar.getInstance();
// Display the current date and time
System.out.println("Current Date and Time : "
+ c.getTime());
c.add((GregorianCalendar.YEAR), -12);
System.out.println("Modified Date and Time : "
+ c.getTime());
// Display hashcode for this calendar
System.out.println("Hash Code of the " +
"modified date and time:" + c.hashCode());
}
}
輸出:
Current Date and Time : Fri Jul 27 11:43:18 UTC 2018 Modified Date and Time : Thu Jul 27 11:43:18 UTC 2006 Hash Code of the modified date and time:-1346149059
參考: https://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html#hashCode()
相關用法
- Java GregorianCalendar add()用法及代碼示例
- Java GregorianCalendar getMaximum()用法及代碼示例
- Java GregorianCalendar getTimeZone()用法及代碼示例
- Java GregorianCalendar setTimeZone()用法及代碼示例
- Java GregorianCalendar getLeastMaximum()用法及代碼示例
- Java GregorianCalendar equals()用法及代碼示例
- Java GregorianCalendar getMinimum()用法及代碼示例
- Java GregorianCalendar clone()用法及代碼示例
- Java GregorianCalendar isLeapYear()用法及代碼示例
- Java GregorianCalendar getGreatestMinimum()用法及代碼示例
- Java Set hashCode()用法及代碼示例
- Java FieldPosition hashCode()用法及代碼示例
- Java YearMonth hashCode()用法及代碼示例
- Java DecimalFormat hashCode()用法及代碼示例
- Java Map hashCode()用法及代碼示例
注:本文由純淨天空篩選整理自RICHIK BHATTACHARJEE大神的英文原創作品 GregorianCalendar hashCode() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。