The java.util.GregorianCalendar.hashCode() is an in-built function in Java which generates hash code for this GregorianCalendar instance.
Syntax:
public int hashCode()
Parameters: This function does not accept any parameters.
Return Values: This function returns an integer value which represents the hash code for this GregorianCalendar instance.
Examples:
Input : Thu Jul 24 00:53:29 UTC 1997 Output : 2121703905 Input : Tue Jul 24 00:54:11 UTC 2018 Output : -909136554
Below programs illustrate the java.util.GregorianCalendar.hashCode() function:
Program 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
Program 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
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html#hashCode()
Recommended Posts:
- GregorianCalendar add() Method in Java
- GregorianCalendar clone() Method in Java
- GregorianCalendar getMinimum() Method in Java
- GregorianCalendar getLeastMaximum() Method in Java
- GregorianCalendar setTimeZone() Method in Java
- GregorianCalendar getTimeZone() Method in Java
- GregorianCalendar isLeapYear() Method in Java
- GregorianCalendar getGreatestMinimum() Method in Java
- GregorianCalendar getMaximum() Method in Java
- GregorianCalendar equals() Method in Java
- LinkedHashSet hashCode() method in Java with Example
- CopyOnWriteArrayList hashCode() method in Java
- ConcurrentLinkedDeque hashCode() method in Java with Example
- Vector hashCode() Method in Java
- BigDecimal hashCode() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



