Date hashCode() method in Java with Examples Last Updated : 07 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The hashCode() method of Java Date class returns a value which is a hash code for this object. Syntax: public int hashCode() Parameters: The function does not accept any parameter. Return Value: It returns a hashCode value for this object. Exception: The function does not throws any exception. Program below demonstrates the above mentioned function: Java // Java code to demonstrate // hashCode() function of Date class import java.util.Date; import java.util.Calendar; public class GfG { // main method public static void main(String[] args) { // creating a Calendar object Calendar c1 = Calendar.getInstance(); // set Month // MONTH starts with 0 i.e. ( 0 - Jan) c1.set(Calendar.MONTH, 11); // set Date c1.set(Calendar.DATE, 05); // set Year c1.set(Calendar.YEAR, 1996); // creating a date object with specified time. Date dateOne = c1.getTime(); System.out.println("Date: " + dateOne); // Prints hash Code System.out.println("HashCode: " + dateOne.hashCode()); } } Output: Date: Thu Dec 05 08:22:04 UTC 1996 HashCode: -629399711 Java // Java code to demonstrate // hashCode() function of Date class import java.util.Date; import java.util.Calendar; public class GfG { // main method public static void main(String[] args) { // creating a Calendar object Calendar c1 = Calendar.getInstance(); // set Month // MONTH starts with 0 i.e. ( 0 - Jan) c1.set(Calendar.MONTH, 11); // set Date c1.set(Calendar.DATE, 21); // set Year c1.set(Calendar.YEAR, 1999); // creating a date object with specified time. Date dateOne = c1.getTime(); System.out.println("Date: " + dateOne); // Prints hash Code System.out.println("HashCode: " + dateOne.hashCode()); } } Output: Date: Tue Dec 21 08:22:09 UTC 1999 HashCode: 871724355 Comment More infoAdvertise with us Next Article DateFormat hashCode() method in Java with Examples T Twinkl Bajaj Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-util-Date +1 More Practice Tags : JavaMisc Similar Reads DateFormat hashCode() method in Java with Examples The hashCode() Method of DateFormat class is used to return the hash code value of this DateFormat object. The hash code is of integer type. Syntax: public int hashCode() Parameters: The method does not take any parameters. Return Value: The method returns the hash code value of this DateFormat obje 2 min read Duration hashCode() method in Java with Examples The hashCode() method of Duration Class in java.time package is used to get the hashCode value of this duration. Syntax: public int hashCode() Parameters: This method do not accepts any parameter. Return Value: This method returns an int value which is the hashCode value of this duration. Below exam 1 min read Calendar hashCode() Method in Java with Examples The hashCode() method in Calendar class is used to return the hash code for this Calendar Object.Syntax: public int hashCode() Parameters: The method does not take any parameters.Return Value: The method returns the hash code value for this calendar object..Below programs illustrate the working of h 2 min read ChronoLocalDate hashCode() method in Java with Examples The hashCode() method of ChronoLocalDate interface in Java is used to get the hashCode value of this ChronoLocalDate object in the integer form. Syntax: public int hashCode() Parameter: This method does not accepts any parameter. Return Value: The function returns a suitable hash code in the form of 1 min read Year hashCode() method in Java with Examples The hashCode() method of Year class in Java is used to get a suitable hash code for the current Year object. Syntax: public int hashCode() Parameter: This method does not accepts any parameter. Return Value: It returns a suitable integral hash code for the year object with which it is used. It never 1 min read Date from() method in Java with Examples The from(Instant inst) method of Java Date class returns an instance of date which is obtained from an Instant object. Syntax: public static Date from(Instant inst) Parameters: The method takes one parameter inst of Instant type which is required to be converted. Return Value: The method returns a d 2 min read Like