Menu
Topics Index
...
`

Formatting Time and Date2927


If you need explanation Read this topic

If you need Answer Take test on this topic

Formatting Time and Date2927
What will be output of the following program?
import java.util.*;
public class FormattingDateAndTime {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        Formatter fmt = new Formatter();
        cal.set(Calendar.HOUR, 02);
        cal.set(Calendar.MINUTE, 55);
        cal.set(Calendar.SECOND, 15);
        fmt.format("%tr", cal);
        System.out.println(fmt);
    }
}

A. 02:55:15 PM
B. 02:55:15 AM
C. 14:55:15
D. Some other output
E. Compilation Error or Runtime Error
Topic: Formatting Date And Time In Java With Example

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer is A because by using set methods time with minutes hours and seconds has been set by defalut the time shows PM at its end as there is no 24 hr format time in the calendar class

Posted by Sai Avinash    2014-08-25 12:53:07


Ans E, because there is no Calender and Formatter classes initialized.

Posted by Damu Surya    2014-08-25 12:54:05


b.time is set using calendr n formattr clas..n AM Is shown

Posted by Wajahat Khan    2014-08-25 13:00:39


b

Posted by Rayapudi Ramya    2014-08-25 14:32:28


Congratulations Sai Avinash. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-26 04:50:09


© meritcampus 2019

All Rights Reserved.

Open In App