Java中的 ZonedDateTime getSecond() 方法及示例
ZonedDateTime类的getSecond()方法用于从此 ZonedDateTime 获取秒字段。此方法返回从 0 到 59 的秒的整数值。
句法:
public int getSecond()
参数:此方法不带任何参数。
返回值:此方法返回一个表示秒的整数,从 0 到 59。
下面的程序说明了 getSecond() 方法:
方案一:
// 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
方案二:
// 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: Java/time/ZonedDateTime.html#getSecond()