Date from() method in Java with Examples Last Updated : 26 Mar, 2019 Comments Improve Suggest changes Like Article Like Report The from(Instant inst) method of Java Date class returns an instance of date which is obtained from an Instant object. Syntax: public static Date from(Instant inst) Parameters: The method takes one parameter inst of Instant type which is required to be converted. Return Value: The method returns a date representing the same point on the timeline as the passing instant. Exceptions: NullPointerException: This is thrown when the instant is left null. IllegalArgumentException: This is thrown when the instant is too large to be represented as a Date. Below programs illustrate the use of from() Method in Java: Example 1: Java // Java code to demonstrate // from() method of Date class import java.time.Instant; import java.util.Date; public class JavaDateDemo { public static void main(String args[]) { // Creating Date Object Date dateOne = new Date(); // Creating Instant object Instant inst = Instant.now(); // Displaying the instant System.out.println( "Present: " + dateOne.from(inst)); } } Output: Present: Tue Mar 26 06:45:40 UTC 2019 Example 2: Java import java.util.Date; import java.util.Calendar; import java.time.Instant; public class GfG { public static void main(String args[]) { // Creating a Calendar object Calendar c1 = Calendar.getInstance(); // Set Month // MONTH starts with 0 i.e. ( 0 - Jan) c1.set(Calendar.MONTH, 00); // Set Date c1.set(Calendar.DATE, 30); // Set Year c1.set(Calendar.YEAR, 2019); // Creating a date object // with specified time. Date dateOne = c1.getTime(); Instant inst = dateOne.toInstant(); System.out.println( "Date: " + dateOne.from(inst)); } } Output: Date: Wed Jan 30 06:45:43 UTC 2019 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Date.html#from-java.time.Instant- Comment More infoAdvertise with us Next Article Date from() method in Java with Examples C chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-util-Date +1 More Practice Tags : JavaMisc Similar Reads Date getTime() method in Java with Examples The getTime() method of Java Date class returns the number of milliseconds since January 1, 1970, 00:00:00 GTM which is represented by Date object. Syntax: public long getTime() Parameters: The function does not accept any parameter. Return Value: It returns the number of milliseconds since January 2 min read DateFormat format() Method in Java with Examples DateFormat class present inside java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. DateFormat class extend 2 min read ChronoLocalDate from() method in Java with Examples The from() method of ChronoLocalDate interface in Java method obtains an instance of ChronoLocalDate from a temporal object. Syntax: public static ChronoLocalDate from(TemporalAccessor temporal) Parameter: This method accepts a parameter temporal which specifies the temporal object to convert and no 1 min read Year from() Method in Java with Examples from() method of the Year class used to get instance of Year from TemporalAccessor object passed as parameter. A TemporalAccessor represents an arbitrary set of date and time information and this method helps to get a year object based on the specified TemporalAccessor object. Syntax: public static 2 min read Date before() method in Java with Examples The before() method of Java Date class tests whether the date is before the specified date or not. Syntax: public boolean before(Date when) Parameters: The function accepts a single parameter when which specifies the date that has to be checked. Return Value: It returns a Boolean value. It will retu 2 min read Like