LocalDate ofInstant() method in Java with Examples Last Updated : 17 May, 2020 Comments Improve Suggest changes Like Article Like Report The ofInstant(Instant instant, ZoneId zone) method of LocalDate class in Java is used to create an instance of LocalDate from an Instant and zone ID. These two parameters are passed to the method and on the basis of those, an instance of LocalDate is created. The calculation of the LocalDate follows the following step. The zone Id and instant are used to obtain the offset from UTC/Greenwich as there can be only one valid offset for each instance. Finally, the local date is calculated using the instant and the obtained offset. Syntax: public static LocalDate ofInstant(Instant instant, ZoneId zone) Parameters: This method accepts two parameters: instant: It is of Instant type and represents the instant passed to create the date. zone: It is of ZoneId type and represent the offset. Return Value: This method returns the localdate. Exceptions: This method throws DateTimeException if the result exceeds the supported range. Note: This method is included in LocalDate class in the latest version of Java only, therefore it might not run in few of the online compilers. Below programs illustrate the ofInstant(Instant instant, ZoneId zone) method in Java: Program 1: Java // Java program to demonstrate // LocalDate.ofInstant( // Instant instant, ZoneId zone) method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // Create LocalDate object LocalDate localdate = LocalDate.ofInstant( Instant.now(), ZoneId.systemDefault()); // Print full date System.out.println("Date: " + localdate); } } Output: Date: 2020-05-13 Program 2: Java // Java program to demonstrate // LocalDate ofInstant() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // Create LocalDate object LocalDate localdate = LocalDate.ofInstant( Instant.now(), ZoneId.systemDefault()); // Print year only System.out.println( "Year: " + localdate.getYear()); } } Output: Year: 2020 References: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#ofInstant(java.time.Instant, java.time.ZoneId) Comment More infoAdvertise with us Next Article LocalDate ofInstant() method in Java with Examples P pp_pankaj Follow Improve Article Tags : Java Java-Functions Java-LocalDate Practice Tags : Java Similar Reads LocalTime ofInstant() method in Java with Examples The ofInstant() method of a LocalTime class is used to obtain an instance of LocalTime from an Instant and zone ID passed as parameters.In this method First, the offset from UTC/Greenwich is obtained using the zone ID and instant. Then, the local time has calculated from the instant and offset. Synt 2 min read LocalDateTime ofInstant() method in Java with Examples ofInstant(Instant instant, ZoneId zone) method of LocalDateTime class in Java is used to create an instance of LocalDateTime using an Instant and zone ID. These two parameters are passed to the method and method returns LocalDateTime on the basis of these two parameters. The calculation of the Local 2 min read LocalDate toString() method in Java with Examples The toString() method of a LocalDate class is used to get this date as a String, such as 2019-01-01.The output will be in the ISO-8601 format uuuu-MM-dd. Syntax: public String toString() Parameters: This method does not accepts any parameters. Return value: This method returns String which is the re 1 min read LocalTime of() method in Java with Examples The of(int hour, int minute) method of the LocalTime class in Java is used to create an instance of LocalTime from the passed values of hour and minute. In this method, the hour and minute are passed in the Integer format and it returns time-based on these values. The values of second and nanosecond 4 min read Locale toString() Method in Java with Examples The toString() method of Locale class in Java is used to return a string representation of this locale. Each element i.e., the language, country or the variant of the locale is separated by underbars Syntax: LOCALE.toString() Parameters: This method does not take any parameters. Return Value: This m 1 min read Like