public static void main(String[] args) { Date d = new Date(); System.out.println(d); // Date类的默认格式 Tue Jul 07 19:17:40 CST 2015 // 以下为DateFormat.getDateInstance(**).format(date)的格式介绍 // -----getDateInstance()格式为 2015-7-7 String dateInstance = DateFormat.getDateInstance().format(d); System.out.println(dateInstance); // -----getDateInstance(DateFormat.DEFAULT) 2015-7-7 String getDateInstanceDefault = DateFormat.getDateInstance( DateFormat.DEFAULT).format(d); System.out.println(getDateInstanceDefault); // ----- getDateInstance(DateFormat.FULL) 2015年7月7日 星期二 String getDateInstanceFull = DateFormat .getDateInstance(DateFormat.FULL).format(d); System.out.println(getDateInstanceFull); // ----- getDateInstance(DateFormat.MEDIUM) 2015-7-7 String getDateInstanceMedium = DateFormat.getDateInstance( DateFormat.MEDIUM).format(d);// medium介质 System.out.println(getDateInstanceMedium); // ----- getDateInstance(DateFormat.SHORT) 15-7-7 String getDateInstanceShort = DateFormat.getDateInstance( DateFormat.SHORT).format(d); System.out.println(getDateInstanceShort); // 自定义格式 // 注:hh表示12时制 HH表示24时制 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); System.out.println(format.format(new Date()));// 2015-07-07 07:31:56 SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(format2.format(new Date()));// 2015-07-07 19:33:03 // calendar // 注意:Calender月份是从0开始的,所以要想获得当前月份Calendar.MONTH + 1 Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); System.out.println(cal.get(Calendar.MONTH) + 1); System.out.println(cal.get(Calendar.DAY_OF_MONTH)); }