Java GregorianCalendar - toZonedDateTime() Method
The java.util.GregorianCalendar.toZonedDateTime() method is used to convert this object to a ZonedDateTime that represents the same point on the time-line as this GregorianCalendar.
Syntax
public ZonedDateTime toZonedDateTime()
Parameters
No parameter is required.
Return Value
Returns a zoned date-time representing the same point on the time-line as this gregorian calendar.
Exception
NA.
Example:
In the example below, the java.util.GregorianCalendar.toZonedDateTime() method is used to convert the given GregorianCalendar to a ZonedDateTime object.
import java.util.*; import java.time.ZonedDateTime; public class MyClass { public static void main(String[] args) { //creating a Calendar object with specified date GregorianCalendar Cal = new GregorianCalendar(2015, 10, 25); //printing the Calendar System.out.println("Gregorian Time is: " + Cal.getTime()); //converting a GregorianCalendar to //ZonedDateTime object ZonedDateTime zdt = Cal.toZonedDateTime(); //printing the ZonedDateTime object System.out.println("ZonedDateTime is: " + zdt); } }
The output of the above code will be:
Gregorian Time is: Wed Nov 25 00:00:00 UTC 2015 ZonedDateTime is: 2015-11-25T00:00Z[Etc/UTC]
❮ Java.util - GregorianCalendar