可以使用toSecondOfDay()Java中LocalTime类中的方法获得一天中几秒钟形式的时间。此方法不需要任何参数,它以一天的秒数形式返回时间。
演示此的程序如下所示-
示例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());