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對象的時代。
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()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
getEra() method does not throw an exception at the time of getting era.
getEra()方法在獲取時代時不會引發異常。
Syntax:
句法:
public Era getEra();Parameter(s):
參數:
None
沒有
Return value:
返回值:
The return type of this method is Era, it returns the Era at this object based on ISO.
此方法的返回類型為Era ,它根據ISO返回此對象處的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
總結
以上是生活随笔為你收集整理的Java LocalDate类| 带示例的getEra()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java中为按钮添加图片_如何在Java
- 下一篇: 定时器mia是什么意思_MIA的完整形式