Java OffsetDateTime getSecond()方法及示例

来源:这里教程网 时间:2026-02-17 20:59:58 作者:

Java OffsetDateTime getSecond()方法及示例

Java中OffsetDateTime类的 getSecond() 方法是用来获取分钟第二字段的值。

语法:

public int getSecond()

参数: 该方法不接受任何参数。

返回值 :它返回从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-

相关推荐