import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormatExample {
public static void main(String args[]) {
Date today = new Date();
System.out.println("Today is : " + today);
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");
String date = DATE_FORMAT.format(today);
System.out.println("Today in dd-MM-yyyy format : " + date);
DATE_FORMAT = new SimpleDateFormat("dd/MM/yy");
date = DATE_FORMAT.format(today);
System.out.println("Today in dd/MM/yy pattern : " + date);
DATE_FORMAT = new SimpleDateFormat("dd-MM-yy:HH:mm:SS");
date = DATE_FORMAT.format(today);
System.out.println("Today in dd-MM-yy:HH:mm:SS : " + date);
DATE_FORMAT = new SimpleDateFormat("dd-MM-yy:HH:mm:SS Z");
date = DATE_FORMAT.format(today);
System.out.println("Today in dd-MM-yy:HH:mm:SSZ : " + date);
}
}
Wynik:
Dzisiaj jest: piątek 02 listopada 16:11:27 IST 2012
Dzisiaj w formacie dd-MM-rrrr: 02-11-2012
Dzisiaj w układzie dd / MM / rr: 11.02.12
Dzisiaj w dd-MM-rr: HH: mm: SS: 02-11-12: 16: 11: 316
Dzisiaj w dd-MM-rr: HH: mm: SSZ: 02-11-12: 16: 11: 316 +0530