Java examples for Date Time:Legacy Date
Formatting date in default formats using DateFormat
import java.text.DateFormat; import java.util.Date; public class Main { public static void main(String[] args) { /* w w w . j av a2 s . c om*/ Date date = new Date(); String strDate = DateFormat.getDateInstance(DateFormat.SHORT).format(date); System.out.println(strDate); strDate = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date); System.out.println(strDate); strDate = DateFormat.getDateInstance(DateFormat.LONG).format(date); System.out.println(strDate); strDate = DateFormat.getDateInstance(DateFormat.FULL).format(date); System.out.println(strDate); } }