Java offsetTime getSecond()方法及示例

来源:这里教程网 时间:2026-02-17 21:00:26 作者:

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

程序2 :

// 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://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#getSecond-

相关推荐