java.time.chrono.JapaneseDate類的now()方法用於從指定時鍾根據日語日曆係統獲取當前日語日期。
用法:
public static JapaneseDate now(Clock clock)
參數:此方法以要形成日文日期的時鍾為對象。
返回值:此方法根據指定的時鍾根據日語日曆係統返回當前日語日期。
下麵是說明now()方法的示例:
範例1:
Java
// Java program to demonstrate now() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing clock
Clock clock = Clock.systemUTC();
// Creating and initializing
// JapaneseDate Object
JapaneseDate hidate
= JapaneseDate.now(clock);
// Display the result
System.out.println("JapaneseDate:"
+ hidate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown:"
+ e);
}
}
}
輸出:
JapaneseDate:Japanese Heisei 32-03-23
範例2:
Java
// Java program to demonstrate now() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing clock
Clock clock = Clock.systemDefaultZone();
// Creating and initializing
// JapaneseDate Object
JapaneseDate hidate
= JapaneseDate.now(clock);
// Display the result
System.out.println("JapaneseDate:"
+ hidate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown:"
+ e);
}
}
}
輸出:
JapaneseDate:Japanese Heisei 32-03-23
參考: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/JapaneseDate.html#now-java.time.Clock-
相關用法
- Java JapaneseDate lengthOfMonth()用法及代碼示例
- Java JapaneseDate now(ZoneId)用法及代碼示例
- Java JapaneseDate lengthOfYear()用法及代碼示例
- Java JapaneseDate minus(long, TemporalUnit)用法及代碼示例
- Java JapaneseDate from()用法及代碼示例
- Java JapaneseDate getChronology()用法及代碼示例
- Java JapaneseDate getLong()用法及代碼示例
- Java JapaneseDate equals()用法及代碼示例
- Java JapaneseDate atTime()用法及代碼示例
- Java JapaneseDate getEra()用法及代碼示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 JapaneseDate now(Clock) method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。