Java Date.setTime(long time)

Syntax

Date.setTime(long time) has the following syntax.

public void setTime(long time)

Example

In the following code shows how to use Date.setTime(long time) method.


//from   w  w w.  j  av a2  s. co  m
import java.util.*;

public class Main {

   public static void main(String[] args) {

      Date date = new Date();

      date.setTime(10000);

      // print the result
      System.out.println("Time after setting:  " + date.toString());
   }
}

The code above generates the following result.