package com.xing.test;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;//import java.util.Calendar;public class DateNow { /** * @param args * 取得年月日、小时分钟秒 */ public static void main(String[] args) { Calendar calender=Calendar.getInstance(); Date date=new Date(); System.out.println("现在的时间是:"+date); calender.setTime(date); System.out.println("现在时间是"+calender.getTime()); int year=calender.get(Calendar.YEAR); int month=calender.get(Calendar.MONTH)+1; int day=calender.get(Calendar.DATE); int minute=calender.get(Calendar.MINUTE); int hour=calender.get(Calendar.HOUR); int second=calender.get(Calendar.SECOND); int weekDay=calender.get(Calendar.DAY_OF_WEEK); System.out.print(year+"年"); System.out.print(month+"月"); System.out.print(day+"日"); System.out.println("星期"+weekDay); System.out.print(hour+"时"); System.out.print(minute+"分"); System.out.print(second+"秒"); /* LocalDateTime dt = LocalDateTime.now(); System.out.println(dt.getYear()); System.out.println(dt.getMonthValue()); // 1 - 12 java8 System.out.println(dt.getDayOfMonth()); System.out.println(dt.getHour()); System.out.println(dt.getMinute()); System.out.println(dt.getSecond());*/ long millionSecond=Calendar.getInstance().getTimeInMillis(); System.out.println("当前毫秒数"+millionSecond); System.currentTimeMillis(); System.out.println("最后一天"+calender.getActualMaximum(Calendar.DAY_OF_MONTH)); SimpleDateFormat adf=new SimpleDateFormat("yyyy年mm月dd日"); System.out.println(adf.format(date)); }} 现在的时间是:Fri Dec 09 09:37:27 CST 2016 现在时间是Fri Dec 09 09:37:27 CST 2016 2016年12月9日星期6 9时37分27秒当前毫秒数1481247447529 最后一天31 2016年37月09日