Java OCA OCP Practice Question 3146

Question

Which one of the following is the correct implementation of a custom time formatter implementation that prints the current time in the format 10:42:30 where 10 is hours (value in range 1-12), 42 is minutes, and 30 is seconds?.

a) System.out.println(new SimpleDateFormat("hh:mm:ss").format(new Date()));
b) System.out.println(new CustomDateFormat("hh:mm:ss").format(new Date()));
c) System.out.println(new SimpleTimeFormat("hh:mm:ss").format(new Date()));
d) System.out.println(new CustomDateTimeFormat("HH:MM:SS").format(new Date()));


a)

Note

In the format hh:mm:ss, h is for the hour in am/pm (with values in 1-12 range), m is for minutes, and s is for seconds.

The class for creating and using custom date or time pattern strings is SimpleDateFormat.

The expression new Date() creates a Date object with the current date and time value.




PreviousNext

Related