Why does the line that prints the current date and time need to use date.toStrin
ID: 3717544 • Letter: W
Question
Why does the line that prints the current date and time need to use date.toString()?
import java.util.Date;
public class Prob24 {
public static void main(String[] args) {
Date date = new Date(1234567);
m1(date);
System.out.printf(" %s", date.getTime());
m2(date);
System.out.printf("%s " , date.getTime());
System.out.printf(" Current date and time is- %s", date.toString());
}
public static void m1(Date date) {
date = new Date(7654321);
}
public static void m2(Date date) {
date.setTime(7654321);
}
}
Explanation / Answer
Answer:
The date.toString() function is used to convert date into following String form.
Day Month Date Hours:Mins:Seconds TimeZone Year
In the given program, the date displayed as,
Thu Jan 01 02:07:34 UTC 1970
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.