import java.text.*; import java.util.*; class Date_formatting { public static void main(String args[]) { Date date = new Date(); SimpleDateFormat sdf; sdf = new SimpleDateFormat("hh:mm:ss"); System.out.print(sdf.format(date)); } }
Note : The program is executed at 3 hour 55 minutes and 4 sec (24 hours time).
a) 3:55:4
b) 3.55.4
c) 55:03:04
d) 03:55:04
d
Explanation: The code “sdf = new SimpleDateFormat(“hh:mm:ss”);” create a SimpleDataFormat class with format hh:mm:ss where h is hours, m is month and s is seconds.
Output:
$ javac Date_formatting.java
$ java Date_formatting
03:55:04