Java Instant toString()方法及示例

Java Instant toString()方法及示例

Instant类toString() 方法使用ISO-8601表示法返回该时刻的字符串表示,使用的格式与DateTimeFormatter.ISO_INSTANT相同。

语法

public String toString()

返回: 该方法返回此瞬间的ISO-8601表示,而不是空。

下面的程序说明了toString()方法。

程序1 :

// Java program to demonstrate
// Instant.toString() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a Instant object
        Instant instant
            = Instant.parse("2018-10-28T19:34:50.63Z");
  
        // print Instant using toString()
        System.out.println("Instant: "
                           + instant.toString());
  
        // addition of 84000 seconds to this instant
        Instant returnedValue
            = instant.plusSeconds(84000);
  
        // print result Instant using toString()
        System.out.println("Returned Instant: "
                           + returnedValue.toString());
    }
}

程序2

// Java program to demonstrate
// Instant.toString() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a Instant object
        Instant instant
            = Instant.parse("2022-06-21T19:34:50.63Z");
  
        // print Instant using toString()
        System.out.println("Instant: "
                           + instant);
    }
}

参考文献: https://docs.oracle.com/javase/10/docs/api/java/time/Instant.html#toString()

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程