w3resource

Java Date.setTime()Method

public void setTime(long time)

The setTime() method is used to set Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Package: java.util

Java Platform: Java SE 8

Syntax:

setTime(long time)

Parameters:

Name Description
time The number of milliseconds.

Return Value:
a hash code value for this object.

Return Value Type: int

Pictorial Presentation of Jave Date setTime() method:

Java Date.setTime() Method

Example: Java Date.setTime() Method

import java.util.Date;

public class Main {
   public static void main(String[] args) {

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

      // set the date for 100000 milliseconds after January 1, 1970 00:00:00 gmt.
      date.setTime(1000000000);

      // print the date
      System.out.println("New date: " + date.toString());
   }
}
 

Output:

New date: Mon Jan 12 13:46:40 UTC 1970

Java Code Editor:

Previous:hashCode Method
Next:toInstant 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://www.w3resource.com/java-tutorial/util/date/java_date_settime.php