Share on Google+Share on Google+

SCJP Module-12 Question-6

Advertisement
The Sample code given below will test your understanding about the Date, DateFormate classes in Java and will also check how the formate the Date in Java.

Given below the sample code :

1. Date dt = new Date();
2. String ds = ?December 21, 2009″;
3. // insert code here
4. try {
5. dt = datef.parse(ds);
6. }
7. catch(ParseException pe) {
8. System.out.println(?Unable to parse ? + ds);
9. }
10. // insert code here

Which code lines should add at line number 3 and 10 to add a day to the Date object?

1. 3.   DateFormat datef = DateFormat.getDateFormat();
    10. dt.setTime( (60 * 60 * 24) + dt.getTime());
2. 3.   DateFormat datef = DateFormat.getDateInstance();
    10. dt.setTime( (1000 * 60 * 60 * 24) + dt.getTime());
3. 3.   DateFormat datef = DateFormat.getDateFormat();
    10. dt.setLocalTime( (1000*60*60*24) + dt.getLocalTime());
4. 3.   DateFormat datef = DateFormat.getDateInstance();
    10. dt.setLocalTime( (60 * 60 * 24) + dt.getLocalTime());

Answer

(2)

 


Advertisements

Advertisement

Posted on: July 22, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.