// Display today's date using a default format for the current locale
DateFormat defaultDate = DateFormat.getDateInstance();
System.out.println(defaultDate.format(new Date()));
// Display the current time using a short time format for the current locale
DateFormat shortTime = DateFormat.getTimeInstance(DateFormat.SHORT);
System.out.println(shortTime.format(new Date()));
// Hours and minutes using 12-hour clock
Calendar c = Calendar.getInstance();
c.setTime(d);
String s = String.format("%tl:%tM %tp", now, d, c); // "3:12 pm"
// current hours and minutes
long now = System.currentTimeMillis();
String sTime = String.format("%tR", now); // "15:12"
// Current month/day/year
Date d = new Date(now);
String sDate = String.format("%tD", d); // "07/13/04"
Labels:
None
Add Comment