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());
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP