当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java LocalTime ofSecondOfDay()用法及代码示例


LocalTime类的ofSecondOfDay()方法用于从second-of-day值获取LocalTime实例。这将返回一个带有指定second-of-day的LocalTime,从0到24 * 60 * 60 – 1作为参数传递。

用法:

public static LocalTime ofSecondOfDay(long secondOfDay)

参数:此方法接受单个参数secondOfDay,即second-of-day,范围为0到24 * 60 * 60 – 1。


返回值:此方法返回从指定的secondOfDay创建的LocalTime实例。

异常:如果second-of-day值无效,则此方法引发DateTimeException。

以下示例程序旨在说明ofSecondOfDay()方法:

示例1:

// Java program to demonstrate 
// LocalTime.ofSecondOfDay() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a nano of day 
        long secondvalue = 14245l; 
  
        // applying ofSecondOfDay() 
        LocalTime value 
            = LocalTime.ofSecondOfDay(secondvalue); 
  
        // print result 
        System.out.println("LocalTime: "
                           + value); 
    } 
}
输出:
LocalTime: 03:57:25

示例2:

// Java program to demonstrate 
// LocalTime.ofSecondOfDay() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a nano of day 
        long second = 24005; 
  
        // applying ofSecondOfDay() 
        LocalTime value 
            = LocalTime.ofSecondOfDay(second); 
  
        // print result 
        System.out.println("LocalTime: "
                           + value); 
    } 
}
输出:
LocalTime: 06:40:05

参考文献: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#ofSecondOfDay(long)



相关用法


注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 LocalTime ofSecondOfDay() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。