Java中OffsetDateTime類的hashCode()方法用於獲取此日期時間實例的哈希碼。
用法:
public int hashCode()
參數:此方法接受不接受任何參數。
返回值:它返回合適的哈希碼。
以下示例程序旨在說明hashCode()方法:
示例1:
// Java program to demonstrate the hashCode() method
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
// parses a date
OffsetDateTime date = OffsetDateTime.parse("2018-12-03T12:30:30+01:00");
// Prints the hash-code of given date
System.out.println("hash-code: " + date.hashCode());
}
}
輸出:
hash-code: 1561872871
程序2:
// Java program to demonstrate the hashCode() method
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
// parses a date
OffsetDateTime date = OffsetDateTime.parse("2016-10-03T12:30:30+01:20");
// Prints the hash-code of given date
System.out.println("hash-code: " + date.hashCode());
}
}
輸出:
hash-code: 1561871543
參考: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html#hashCode–
相關用法
- Java OffsetDateTime until()用法及代碼示例
- Java OffsetDateTime with()用法及代碼示例
- Java OffsetDateTime from()用法及代碼示例
- Java OffsetDateTime get()用法及代碼示例
- Java OffsetDateTime getLong()用法及代碼示例
- Java OffsetDateTime getHour()用法及代碼示例
- Java OffsetDateTime getMinute()用法及代碼示例
- Java OffsetDateTime withDayOfMonth()用法及代碼示例
- Java OffsetDateTime withNano()用法及代碼示例
- Java OffsetDateTime query()用法及代碼示例
- Java OffsetDateTime isEqual()用法及代碼示例
- Java OffsetDateTime getMonth()用法及代碼示例
- Java OffsetDateTime getDayOfWeek()用法及代碼示例
- Java OffsetDateTime getMonthValue()用法及代碼示例
- Java OffsetDateTime getNano()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetDateTime hashCode() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。