Sunday, June 14, 2026
HomeLanguagesJavaChronoZonedDateTime from() method in Java with Examples

ChronoZonedDateTime from() method in Java with Examples

The from() method of ChronoZonedDateTime interface in Java method obtains an instance of ChronoZonedDateTime from a temporal object.

Syntax:

static ChronoZonedDateTime 
    from(TemporalAccessor temporal)

Parameter: This method accepts a parameter temporal which specifies the temporal object to convert and not null.

Return Value: It returns the ChronoZonedDateTime and not null.

Exceptions: The function throws only DateTimeException which occurs if it is unable to convert it to a ChronoZonedDateTime.

Below programs illustrate the from() method of ChronoZonedDateTime in Java:

Note: The output will change on every run.




// Program to illustrate the from() method
  
import java.util.*;
import java.time.*;
import java.time.chrono.*;
  
public class GfG {
    public static void main(String[] args)
    {
  
        ChronoZonedDateTime dt
            = ZonedDateTime.from(ZonedDateTime.now());
  
        System.out.println(dt);
    }
}


Output:

2019-05-26T12:36:04.419Z[Etc/UTC]

Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoZonedDateTime.html#from-java.time.temporal.TemporalAccessor-

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS