Java LocalDate类| 带示例的getEra()方法
LocalDate類的getEra()方法 (LocalDate Class getEra() method)
getEra() method is available in java.time package.
getEra()方法在java.time包中可用。
getEra() method is used to get the era applicable for this LocalDate object.
getEra()方法用于獲取適用于此LocalDate對(duì)象的時(shí)代。
getEra() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
getEra()方法是一個(gè)非靜態(tài)方法,只能通過(guò)類對(duì)象訪問(wèn),如果嘗試使用類名稱訪問(wèn)該方法,則會(huì)收到錯(cuò)誤消息。
getEra() method does not throw an exception at the time of getting era.
getEra()方法在獲取時(shí)代時(shí)不會(huì)引發(fā)異常。
Syntax:
句法:
public Era getEra();Parameter(s):
參數(shù):
None
沒(méi)有
Return value:
返回值:
The return type of this method is Era, it returns the Era at this object based on ISO.
此方法的返回類型為Era ,它根據(jù)ISO返回此對(duì)象處的Era。
Example:
例:
// Java program to demonstrate the example // of Era getEra() method of LocalDateimport java.time.*; import java.time.chrono.*;public class GetEraOfLocalDate {public static void main(String args[]) {// Instantiates two LocalDateLocalDate l_da1 = LocalDate.parse("2007-04-05");LocalDate l_da2 = LocalDate.of(-2008, Month.MAY, 10);// Display l_da1,l_da2System.out.println("LocalDate l_da1 and l_da2: ");System.out.println("l_da1: " + l_da1);System.out.println("l_da2: " + l_da2);System.out.println();// Here, this method returns the era// applicable at this date l_da1Era get_era = l_da1.getEra();// Display get_eraSystem.out.println("l_da1.getEra(): " + get_era);// Here, this method returns the era// applicable at this date l_da2get_era = l_da2.getEra();// Display get_eraSystem.out.println("l_da2.getEra(): " + get_era);} }Output
輸出量
LocalDate l_da1 and l_da2: l_da1: 2007-04-05 l_da2: -2008-05-10l_da1.getEra(): CE l_da2.getEra(): BCE翻譯自: https://www.includehelp.com/java/localdate-getera-method-with-example.aspx
總結(jié)
以上是生活随笔為你收集整理的Java LocalDate类| 带示例的getEra()方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java中为按钮添加图片_如何在Java
- 下一篇: Java FilterInputStre