Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote