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);
}
}
आउटपुट:
आज है: शुक्र नवंबर 02 16:11:27 IST 2012
आज dd-MM-yyyy प्रारूप में: 02-11-2012
आज dd / MM / yy पैटर्न में: 02/11/12
आज dd-MM-yy: HH: mm: SS: 02-11-12: 16: 11: 316
आज dd-MM-yy: HH: mm: SSZ: 02-11-12: 16: 11: 316 +0530