LocalDateTime類的getSecond()方法用於返回second-of-minute字段。此方法返回一個介於0到59之間的整數值,即一分鍾的秒數。
用法:
public int getSecond()
參數:此方法不接受任何參數。
返回值:此方法返回一個表示second-of-minute的整數值,範圍為0至59。
以下示例程序旨在說明LocalDateTime.getSecond()方法:
示例1:
// Java program to demonstrate
// LocalDateTime.getSecond() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a LocalDateTime Object
LocalDateTime local
= LocalDateTime.parse("2018-12-03T12:39:10");
// get SecondOfMinute
int secondOfMinute = local.getSecond();
// print result
System.out.println("SecondOfMinute: "
+ secondOfMinute);
}
}
輸出:
SecondOfMinute: 10
示例2:
// Java program to demonstrate
// LocalDateTime.getSecond() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a LocalDateTime Object
LocalDateTime local
= LocalDateTime.parse("2019-01-28T22:29:59");
// get SecondOfMinute
int secondOfMinute = local.getSecond();
// print result
System.out.println("SecondOfMinute: "
+ secondOfMinute);
}
}
輸出:
SecondOfMinute: 59
參考:https://docs.oracle.com/javase/9/docs/api/java/time/LocalDateTime.html#getSecond–
相關用法
- Java OffsetDateTime getSecond()用法及代碼示例
- Java LocalTime getSecond()用法及代碼示例
- Java ZonedDateTime getSecond()用法及代碼示例
- Java LocalDateTime with()用法及代碼示例
- Java LocalDateTime now()用法及代碼示例
- Java LocalDateTime plus()用法及代碼示例
- Java LocalDateTime until()用法及代碼示例
- Java LocalDateTime from()用法及代碼示例
- Java LocalDateTime getNano()用法及代碼示例
- Java LocalDateTime isEqual()用法及代碼示例
- Java LocalDateTime plusDays()用法及代碼示例
- Java LocalDateTime plusMinutes()用法及代碼示例
- Java LocalDateTime plusHours()用法及代碼示例
- Java LocalDateTime plusMonths()用法及代碼示例
- Java LocalDateTime isBefore()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 LocalDateTime getSecond() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。