Date toInstant() Method in Java with Examples Last Updated : 26 Mar, 2019 Comments Improve Suggest changes Like Article Like Report The toInstant() method of Date class in Java is used to convert a Date object to an Instant object. An Instant is created during the conversion which is used to represent the same point on the timeline as this Date. Syntax: public Instant toInstant() Parameters: The method does not take any parameters. Return Value: The method returns an Instant representing the same point on the timeline as this Date. Below programs illustrate the use of toInstant() method in Java: Example 1: Java // Java code to demonstrate // toInstant() method of Date class 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( "Original Date: " + dateOne.toString()); System.out.println( "Instant: " + inst); } } Output: Original Date: Wed Jan 30 06:01:46 UTC 2019 Instant: 2019-01-30T06:01:46.730Z Example 2: Java // Java code to demonstrate // clone() method of Date class 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, 06); // Set Date c1.set(Calendar.DATE, 12); // Set Year c1.set(Calendar.YEAR, 1996); // Creating a date object // with specified time. Date dateOne = c1.getTime(); Instant inst = dateOne.toInstant(); System.out.println( "Original Date: " + dateOne.toString()); System.out.println( "Instant: " + inst); } } Output: Original Date: Fri Jul 12 06:01:49 UTC 1996 Instant: 1996-07-12T06:01:49.766Z Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Date.html#toInstant-- Comment More infoAdvertise with us Next Article Date toInstant() Method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-util-Date +1 More Practice Tags : JavaMisc Similar Reads Date toString() method in Java with Examples The toString() method of Java Date class converts this date object into a String in form "dow mon dd hh:mm:ss zzz yyy". This method overrides toString in class object. Syntax: public String toString() Parameters: The function does not accept any parameter. Return Value: It method returns a string re 2 min read Date setTime() method in Java with Examples The setTime() method of Java Date class sets a date object. It sets date object to represent time milliseconds after January 1, 1970 00:00:00 GMT. Syntax: public void setTime(long time) Parameters: The function accepts a single parameter time which specifies the number of milliseconds. Return Value: 2 min read OffsetTime atDate() method in Java with examples The atDate() method of OffsetTime class in Java combines this time with a date to create a OffsetDateTime. Syntax : public OffsetDateTime atDate(LocalDate date) Parameter: This method accepts a single parameter date which specifies the date to combine with, not null. Return Value: It returns the Off 2 min read ChronoZonedDateTime toInstant() method in Java with Examples The toInstant() method of a ChronoZonedDateTime class is used to convert this ChronoZonedDateTime to the Instant. Syntax: default Instant toInstant() Parameters: This method do not accepts any parameter. Return value: This method returns Instant which is the same Instant represented by this ChronoZo 1 min read MonthDay atYear() method in Java with Examples The atYear() method of MonthDay class in Java combines this month-day with a year to create a LocalDate. Syntax: public LocalDate atYear(int year) Parameter: This method accepts a parameter year which specifies the year to use which is in range [MIN_YEAR, MAX_YEAR] Returns: The function returns the 1 min read ChronoLocalDateTime toInstant() method in Java with Examples The toInstant() method of a ChronoLocalDateTime class is used to convert this ChronoLocalDateTime to an Instant. The method combines this ChronoLocalDateTime with the offset passed as parameters to calculate the Instant. Syntax: default Instant toInstant(ZoneOffset offset) Parameters: This method ac 2 min read util.date class methods in Java with Examples Following are some important date class methods : .toString() : java.util.Date.tostring() method is a java.util.Date class method.It displays the Current date and time. Here Date object is converted to a string and represented as: day mon dd hh:mm:ss zz yyyy day : day of the week mon : month dd : da 5 min read MinguoDate atTime() method in Java with Example The atTime() method of java.time.chrono.MinguoDate class is used to add up this MinguoDate time with a local time for producing an equivalent date and time. Syntax: public final ChronoLocalDateTime atTime(LocalTime localTime) Parameter: This method takes the object of type LocalTime as a parameter. 2 min read DateFormat setLenient() Method in Java with Examples The setLenient(boolean leniency) method in DateFormat class is used to specify whether the interpretation of the date and time of this DateFormat object is to be lenient or not. Syntax: public void setLenient(boolean leniency) Parameters: The method takes one parameter leniency of the boolean type t 2 min read Date from() method in Java with Examples 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 d 2 min read Like