Java 中 LocalDateTime getSecond() 方法


在 Java 中,可以使用 `LocalDateTime` 類中的 `getSecond()` 方法獲取特定 `LocalDateTime` 的秒數。此方法不需要引數,它返回 0 到 59 範圍內的秒數。

以下是演示此方法的程式:

示例

 線上演示

import java.time.*;
public class Demo {
   public static void main(String[] args) {
      LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");
      System.out.println("The LocalDateTime is: " + ldt);
      System.out.println("The second is: " + ldt.getSecond());
   }
}

輸出

The LocalDateTime is: 2019-02-18T23:15:30
The second is: 30

現在讓我們來了解一下上述程式。

首先顯示 `LocalDateTime`。然後使用 `getSecond()` 方法顯示 `LocalDateTime` 的秒數。下面是一個演示此方法的程式碼片段:

LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");
System.out.println("The LocalDateTime is: " + ldt);
System.out.println("The second is: " + ldt.getSecond());

更新於:2019 年 7 月 30 日

55 次瀏覽

啟動您的職業生涯

透過完成課程成為認證專業人士

開始
廣告
© . All rights reserved.