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


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


ZonedDateTime類的getSecond()方法用於從該ZonedDateTime獲取second-of-minute字段。此方法返回從0到59的第二個整數值。

用法:

public int getSecond()

參數:此方法不帶任何參數。


返回值:此方法返回一個表示second-of-minute的整數,範圍是0到59。

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

示例1:

// Java program to demonstrate 
// ZonedDateTime.getSecond() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a ZonedDateTime object 
        ZonedDateTime zoneddatetime 
            = ZonedDateTime.parse( 
                "2018-12-06T19:21:12.123+05:30[Asia/Calcutta]"); 
  
        // get second-of-minute field 
        int value = zoneddatetime.getSecond(); 
  
        // print result 
        System.out.println("second-of-minute:" + value); 
    } 
}
輸出:
second-of-minute:12

示例2:

// Java program to demonstrate 
// ZonedDateTime.getSecond() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a ZonedDateTime object 
        ZonedDateTime zoneddatetime 
            = ZonedDateTime.parse( 
                "2018-10-25T23:12:38.543+02:00[Europe/Paris]"); 
  
        // get second-of-minute field 
        int value = zoneddatetime.getSecond(); 
  
        // print result 
        System.out.println("second-of-minute:" + value); 
    } 
}
輸出:
second-of-minute:38

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



相關用法


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