一、利用Calender获取单个时间的一部分
Calendar c = Calendar.getInstance();
//取得年月日
year = c.get(Calendar.YEAR)
month = c.get(Calendar.MONTH)
day = c.get(Calendar.DAY_OF_MONTH)
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE)
实例:
Calender实现日历
二、利用DateFormat格式化的获取时间
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss EEEE");//设置格式
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);