w3resource

Java Date.getTime() Method

public long getTime()

The getTime() method is used to get the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Package: java.util

Java Platform: Java SE 8

Syntax:

getTime()

Return Value:
the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.

Return Value Type:

Pictorial Presentation of Jave Date getTime() method:

Java Date.getTime() Method

Example: Java Date.getTime() Method

import java.util.Date;
import java.time.Instant;
public class Main {
   public static void main(String[] args) {

      // create a date
       Date date = new Date(2012, 2, 2);

      // Converts the said Date object to an Instant
       Instant i = date.toInstant();
       System.out.println(i);
   }
}
 

Output:

3912-03-02T00:00:00Z

Java Code Editor:

Previous:from Method
Next:hashCode Method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/java-tutorial/util/date/java_date_gettime.php