- public static void main(String[] args) {
- Calendar ca = Calendar.getInstance();
- int year = ca.get(Calendar.YEAR);//获取年份
- int month=ca.get(Calendar.MONTH);//获取月份
- int day=ca.get(Calendar.DATE);//获取日
- int minute=ca.get(Calendar.MINUTE);//分
- int hour=ca.get(Calendar.HOUR);//小时
- int second=ca.get(Calendar.SECOND);//秒
- int WeekOfYear = ca.get(Calendar.DAY_OF_WEEK);
- System.out.println("用Calendar.getInstance().getTime()方式显示时间: " + ca.getTime());
- System.out.println("用Calendar获得日期是:" + year +"年"+ month +"月"+ day + "日");
- System.out.println("用Calendar获得时间是:" + hour +"时"+ minute +"分"+ second +"秒");
- System.out.println(WeekOfYear);
- }
复制代码 |