Java中的OffsetDateTime類的getSecond()方法用於獲取second-of-minute字段的值。
用法:
public int getSecond()
參數:此方法接受不接受任何參數。
返回值:它返回second-of-minute,範圍從0到59。
以下示例程序旨在說明getSecond()方法:
示例1:
// Java program to demonstrate the getSecond() method
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
// parses a date
OffsetDateTime date = OffsetDateTime.parse("2018-12-03T12:30:30+01:00");
// Prints the second of given date
System.out.println("second: " + date.getSecond());
}
}
輸出:
second: 30
程序2:
// Java program to demonstrate the getSecond() method
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
// parses a date
OffsetDateTime date = OffsetDateTime.parse("2016-10-03T12:30:30+01:20");
// Prints the second of given date
System.out.println("second: " + date.getSecond());
}
}
輸出:
second: 30
參考: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html#getSecond–
相關用法
- Java LocalTime getSecond()用法及代碼示例
- Java LocalDateTime getSecond()用法及代碼示例
- Java ZonedDateTime getSecond()用法及代碼示例
- Java OffsetDateTime from()用法及代碼示例
- Java OffsetDateTime with()用法及代碼示例
- Java OffsetDateTime until()用法及代碼示例
- Java OffsetDateTime get()用法及代碼示例
- Java OffsetDateTime minusDays()用法及代碼示例
- Java OffsetDateTime withYear()用法及代碼示例
- Java OffsetDateTime compareTo()用法及代碼示例
- Java OffsetDateTime getDayOfYear()用法及代碼示例
- Java OffsetDateTime adjustInto()用法及代碼示例
- Java OffsetDateTime withMonth()用法及代碼示例
- Java OffsetDateTime getDayOfWeek()用法及代碼示例
- Java OffsetDateTime minusMinutes()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetDateTime getSecond() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。