How to display date in different formats ?


Levels of difficulty: / perform operation:



JAVA Program

import java.text.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Date dt = new Date(1000000000000L);
		DateFormat[] dtformat = new DateFormat[6];
		dtformat[0] = DateFormat.getInstance();
		dtformat[1] = DateFormat.getDateInstance();
		dtformat[2] = DateFormat.getDateInstance(DateFormat.MEDIUM);
		dtformat[3] = DateFormat.getDateInstance(DateFormat.FULL);
		dtformat[4] = DateFormat.getDateInstance(DateFormat.LONG);
		dtformat[5] = DateFormat.getDateInstance(DateFormat.SHORT);
		for (DateFormat dateform : dtformat)
		         System.out.println(dateform.format(dt));
	}
}



Output

9/9/01 7:16 AM
Sep 9, 2001
Sep 9, 2001
Sunday, September 9, 2001
September 9, 2001
9/9/01





Quantitative Aptitude
Reasoning
Programming
Interview