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


Java LocalTime toSecondOfDay()用法及代碼示例


LocalTime類的toSecondOfDay()方法用於從該LocalTime以秒為單位返回時間。此方法返回的值介於0到24 * 60 * 60 – 1之間。

用法:

public int toSecondOfDay()

參數:此方法不接受任何參數。


返回值:此方法返回一個long值,它是一天中的第二個值,並且與該時間相等。

以下示例程序旨在說明toSecondOfDay()方法:

示例1:

// Java program to demonstrate 
// LocalTime.toSecondOfDay() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a LocalTime object 
        LocalTime time 
            = LocalTime.parse("19:34:50.63"); 
  
        // extract second of day from toSecondOfDay() 
        int value = time.toSecondOfDay(); 
  
        // print result 
        System.out.println("Second of day: "
                           + value); 
    } 
}
輸出:
Second of day: 70490

示例2:

// Java program to demonstrate 
// LocalTime.toSecondOfDay() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a LocalTime object 
        LocalTime time 
            = LocalTime.parse("23:21:45.98"); 
  
        // extract Second of day from toSecondOfDay() 
        int value = time.toSecondOfDay(); 
  
        // print result 
        System.out.println("Second of day: "
                           + value); 
    } 
}
輸出:
Second of day: 84105

參考: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#toSecondOfDay()



相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 LocalTime toSecondOfDay() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。