LocalTime 类中的 ofSecondOfDay() 方法
可以使用 Java 中 LocalTime 类的 ofSecondOfDay() 方法,通过一天中的秒数来获取一个 LocalTime 对象。此方法需要一个参数,即一天中的秒数,并且它将返回一天中的秒数的 LocalTime 对象。
演示这一点的一个程序如下
示例
import java.time.*;
public class Demo {
public static void main(String[] args) {
long seconds = 18930;
System.out.println("The seconds of the day: " + seconds);
System.out.println("The LocalTime is: " + LocalTime.ofSecondOfDay(seconds));
}
}输出
The seconds of the day: 18930 The LocalTime is: 05:15:30
现在让我们了解一下上面的程序。
首先显示一天中的秒数。然后使用 ofSecondOfDay() 方法通过一天中的秒数获取 LocalTime 对象并打印出来。演示这一点的代码段如下
long seconds = 18930;
System.out.println("The seconds of the day: " + seconds);
System.out.println("The LocalTime is: " + LocalTime.ofSecondOfDay(seconds));
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP