Instant toString() method in Java with Examples
Last Updated :
28 Nov, 2018
The toString() method of Instant class returns string representation of this instant using ISO-8601 representation and format used is the same as DateTimeFormatter.ISO_INSTANT.
Syntax:
public String toString()
Returns: This method returns an ISO-8601 representation of this instant, not null.
Below programs illustrate the toString() method:
Program 1:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
Instant instant
= Instant.parse( "2018-10-28T19:34:50.63Z" );
System.out.println( "Instant: "
+ instant.toString());
Instant returnedValue
= instant.plusSeconds( 84000 );
System.out.println( "Returned Instant: "
+ returnedValue.toString());
}
}
|
Program 2:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
Instant instant
= Instant.parse( "2022-06-21T19:34:50.63Z" );
System.out.println( "Instant: "
+ instant);
}
}
|
References: https://docs.oracle.com/javase/10/docs/api/java/time/Instant.html#toString()
Share your thoughts in the comments
Please Login to comment...