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.
public void setTime(long time)
Parameters: The function accepts a single parameter time which specifies the number of milliseconds.
Return Value: It method has no return value.
Exception: The function does not throws any exception.
Program below demonstrates the above mentioned function:
Date initially: Wed Jan 02 09:34:03 UTC 2019 Date after setting the time: Thu Jan 01 00:00:01 UTC 1970
Date initially: Thu Dec 05 09:32:53 UTC 1996 Date after setting the time: Thu Jan 01 00:16:40 UTC 1970
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.