Text Formatting(Computer Science > Java Program ) Questions and Answers
What is the output of this program?
import java.text.*;
import java.util.*;
class Date_formatting {
public static void main(String args[]) {
Date date = new Date();
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("z");
System.out.print(sdf.format(date));
}
}
Note : The program is executed at 3 hour 55 minutes and 4 sec on Monday, 15 July(24 hours time).
Explanation:-
Answer: Option D. -> PDTformat string "z" is used to print time zone.
Output:
$ javac Date_formatting.java
$ java Date_formatting
PDT
What is the output of this program?
import java.text.*;
import java.util.*;
class Date_formatting {
public static void main(String args[]) {
Date date = new Date();
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("E MMM dd yyyy");
System.out.print(sdf.format(date));
}
}
Note: The program is executed at 3 hour 55 minutes and 4 sec on Monday, 15 July(24 hours time).
Explanation:-
Answer: Option A. -> Mon Jul 15 2013None.
Output:
$ javac Date_formatting.java
$ java Date_formatting
Mon Jul 15 2013
What is the output of this program?
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).
Explanation:-
Answer: Option D. -> 03:55:04The code "sdf = new SimpleDateFormat("hh:mm:ss");" create a SimpleDataFormat
What is the output of this program?
import java.text.*;
import java.util.*;
class Date_formatting {
public static void main(String args[]) {
Date date = new Date();
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("mm:hh:ss");
System.out.print(sdf.format(date));
}
}
Note : The program is executed at 3 hour 55 minutes and 4 sec (24 hours time).
Explanation:-
Answer: Option C. -> 55:03:04None.
Output:
$ javac Date_formatting.java
$ java Date_formatting
55:03:04
Explanation:-
Answer: Option B. -> SimpleDateFormatThe DateFormat is a concrete subclass of DateFormat. It allows you to define your
own formatting patterns that are used to display date and time information.