Java中的 OffsetTime getSecond() 示例
Java中 OffsetTime 类的getSecond()方法用于从这个 offsetTime 实例中获取秒字段的值。
句法 :
public int getSecond()
参数:此方法接受不接受任何参数。
返回值:返回秒数,范围为 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
方案二:
// 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: Java/time/OffsetTime.html#getSecond–