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:
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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4