Saturday, August 10, 2024

SimpleDateFormat MCQs

 SimpleDateFormat MCQs

Which package does the SimpleDateFormat class belong to in Java?


A. java.time

B. java.util

C. java.text

D. java.lang

What is the purpose of the SimpleDateFormat class in Java?


A. To perform date arithmetic.

B. To format and parse dates in a locale-sensitive manner.

C. To convert dates to strings.

D. To store date information.

Which method is used to format a Date object into a string in a specific pattern?


A. formatDate(Date date)

B. toString(Date date)

C. toPattern(Date date)

D. format(Date date)

How do you create a SimpleDateFormat object with the pattern "dd/MM/yyyy"?


A. new SimpleDateFormat("dd-MM-yyyy")

B. new SimpleDateFormat("MM/dd/yyyy")

C. new SimpleDateFormat("dd/MM/yyyy")

D. new SimpleDateFormat("yyyy/MM/dd")

What does the pattern "yyyy-MM-dd" represent in SimpleDateFormat?


A. Day-Month-Year

B. Year-Month-Day

C. Month-Day-Year

D. Year-Day-Month

Which method in SimpleDateFormat is used to parse a string into a Date object?


A. parseDate(String source)

B. toDate(String source)

C. stringToDate(String source)

D. parse(String source)

What will be the output of the following code?


java

Copy code

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

String date = sdf.format(new Date(0));

System.out.println(date);

A. 01/01/1970

B. 31/12/1969

C. 01/01/1971

D. 02/01/1970

How do you set a specific time zone for a SimpleDateFormat object?


A. setTimeZone(TimeZone zone)

B. setZone(TimeZone zone)

C. setDefaultTimeZone(TimeZone zone)

D. setTimeZone(ZoneId zone)

Which pattern symbol represents the minute in hour in SimpleDateFormat?


A. M

B. m

C. n

D. min

What is the result of the following code?


java

Copy code

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

String date = sdf.format(new Date());

System.out.println(date);

A. Current date and time in "yyyy-MM-dd HH:mm

" format

B. Current date and time in "yyyy/MM/dd HH:mm

" format

C. Current date in "yyyy-MM-dd" format

D. Current date and time in "dd/MM/yyyy HH:mm

" format

How do you change the date format pattern of an existing SimpleDateFormat object?


A. setPattern(String pattern)

B. changePattern(String pattern)

C. applyPattern(String pattern)

D. updatePattern(String pattern)

Which pattern symbol is used for a 24-hour format of an hour in SimpleDateFormat?


A. hh

B. HH

C. kk

D. KK

What will the pattern "EEE, MMM d, ''yy" display in SimpleDateFormat?


A. Full day name, full month name, day, and full year

B. Abbreviated day name, full month name, day, and last two digits of the year

C. Abbreviated day name, full month name, day, and full year

D. Abbreviated day name, abbreviated month name, day, and last two digits of the year

Which pattern symbol is used for the day of the week in SimpleDateFormat?


A. D

B. E

C. F

D. W

What will be the output if a SimpleDateFormat object is created with the pattern "yyyy.MM.dd G 'at' HH:mm

z"?


A. Date with full year, month, day, era, time, and time zone

B. Date with year, month, day, era, time, and time zone in abbreviated form

C. Date with year, month, day, and time

D. Date with year, month, and time zone only

How do you obtain the pattern string of a SimpleDateFormat object?


A. getPattern()

B. toPattern()

C. getFormat()

D. toString()

What will the pattern "yyyy-MM-dd'T'HH:mm

.SSSXXX" display in SimpleDateFormat?


A. Date and time in ISO 8601 format

B. Date and time with time zone in ISO 8601 format

C. Date and time without milliseconds and time zone

D. Date only

Which method can you use to convert a Date object to a string using SimpleDateFormat?


A. format(Date date)

B. parse(Date date)

C. stringify(Date date)

D. toString(Date date)

What will happen if the SimpleDateFormat pattern is invalid or incorrect?


A. Throws an IllegalArgumentException

B. Returns null

C. Uses a default pattern

D. Throws a ParseException

How do you set the locale of a SimpleDateFormat object?


A. setLocale(Locale locale)

B. applyLocale(Locale locale)

C. changeLocale(Locale locale)

D. setTimeZone(Locale locale)

Answers:

C. java.text

B. To format and parse dates in a locale-sensitive manner.

D. format(Date date)

C. new SimpleDateFormat("dd/MM/yyyy")

B. Year-Month-Day

D. parse(String source)

A. 01/01/1970

A. setTimeZone(TimeZone zone)

B. m

B. Current date and time in "yyyy/MM/dd HH:mm

" format

C. applyPattern(String pattern)

B. HH

B. Abbreviated day name, full month name, day, and last two digits of the year

B. E

A. Date with full year, month, day, era, time, and time zone

B. toPattern()

A. Date and time in ISO 8601 format

A. format(Date date)

A. Throws an IllegalArgumentException

A. setLocale(Locale locale)

No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...