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


Java OffsetTime getSecond()用法及代碼示例


Java中OffsetTime類的getSecond()方法用於從此offsetTime實例獲取second-of-minute字段的值。

用法:

public int getSecond()

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


返回值:它返回second-of-minute,範圍從0到59。

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

示例1:

// Java program to demonstrate the getSecond() method 
  
import java.time.OffsetTime; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // Parses the time 
        OffsetTime time = OffsetTime.parse("15:10:30+07:00"); 
  
        // gets the second in time 
        System.out.println("second: " + time.getSecond()); 
    } 
}
輸出:
second: 30
輸出:
second: 30

程序2

// Java program to demonstrate the getSecond() method 
  
import java.time.OffsetTime; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // Parses the time 
        OffsetTime time = OffsetTime.parse("11:30:50+06:00"); 
  
        // gets the second in time 
        System.out.println("second: " + time.getSecond()); 
    } 
}
輸出:
second: 50

參考: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#getSecond–



相關用法


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