當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。