Java Convert ZonedDateTime to Instant
In this Java core tutorial we learn how to convert a java.time.ZonedDateTime object into java.time.Instant object in Java programming language.
How to convert ZonedDateTime to Instant in Java
In Java, to convert a ZonedDateTime object to Instant object we can use the ZonedDateTime.toInstant() method as the Java program below.
import java.time.Instant; import java.time.ZonedDateTime; public class ConvertZonedDateTimeToInstantExample1 public static void main(String. args) ZonedDateTime zonedDateTime = ZonedDateTime.now(); Instant instant = zonedDateTime.toInstant(); System.out.println("ZonedDateTime: " + zonedDateTime); System.out.println("Instant: " + instant); > >
ZonedDateTime: 2022-05-06T23:47:20.146853700+07:00[Asia/Bangkok] Instant: 2022-05-06T16:47:20.146853700Z