Assume the following code executes on the following date and time:
Date: 2009 Jan 21 Time: 21:45:12
Date today = new Date(); //INSERT CODE HERE System.out.println(dateFmt.format(today)); System.out.println(timeFmt.format(today));
Which of the following lines of code, when inserted at //INSERT CODE HERE, will output the date and time that coincides with the UK's Locale?.
21/01/09 21:45:12
a Locale.setDefault(Locale.UK); DateFormat dateFmt = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat timeFmt = DateFormat.getTimeInstance(DateFormat.MEDIUM); b DateFormat dateFmt = new SimpleDateFormat("dd/MM/yy"); DateFormat timeFmt = new SimpleDateFormat("HH:mm:ss"); c DateFormat dateFmt = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat timeFmt = DateFormat.getTimeInstance(DateFormat.MEDIUM); d DateFormat dateFmt = DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK);//from w w w .j av a2s. co m DateFormat timeFmt = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.UK);
a, b, d
Option (c) is incorrect because this code would format the date and time values according to the host's default locale.
The output should be formatted according to Locale.
UK or by using the exact pattern.