Java 中的 LocalTime toSecondOfDay() 方法


Java 中的 LocalTime 類的 toSecondOfDay() 方法可用於獲得日中的時間(以秒為單位)。此方法不需要引數,且以日中的時間(以秒為單位)的形式返回時間。

實現此功能的程式如下 −

示例

 即時演示

import java.time.*;
public class Main {
   public static void main(String[] args) {
      LocalTime lt = LocalTime.parse("05:15:30");
      System.out.println("The LocalTime is: " + lt);
      System.out.println("The seconds of the day are: " + lt.toSecondOfDay());
   }
}

輸出

The LocalTime is: 05:15:30
The seconds of the day are: 18930

現在讓我們瞭解上述程式。

首先顯示 LocalTime。然後使用 toSecondOfDay() 方法以日中的時間(以秒為單位)的形式獲取時間。下面提供的程式碼片段演示了此內容 −

LocalTime lt = LocalTime.parse("05:15:30");
System.out.println("The LocalTime is: " + lt);
System.out.println("The seconds of the day are: " + lt.toSecondOfDay());

更新時間:30-Jul-2019

45 次瀏覽

啟動你的 職業

完成課程獲得認證

開始
廣告
© . All rights reserved.