Learn from:http://blog.csdn.net/sunhuwh/article/details/39161323
Public classCalendartest { Public Static voidMain (string[] args) {//get current year, month, dateCalendar Cale =NULL; Cale=calendar.getinstance (); intYear =Cale.get (calendar.year); intmonth = Cale.get (calendar.month) + 1; intDay =Cale.get (calendar.date); inthour =Cale.get (Calendar.hour_of_day); intminute =Cale.get (Calendar.minute); intSecond =Cale.get (Calendar.second); intDow =Cale.get (Calendar.day_of_week); intDom =Cale.get (Calendar.day_of_month); intDoy =Cale.get (calendar.day_of_year); System.out.println ("Current Date:" +cale.gettime ()); System.out.println ("Year:" +Year ); System.out.println ("Month:" +month); System.out.println ("Day:" +Day ); System.out.println ("Hour:" +hour); System.out.println ("Minute:" +minute); System.out.println ("Second:" +second); System.out.println ("Day of Week:" +Dow); System.out.println ("Day of Month:" +DOM); System.out.println ("Day of the Year:" +Doy); //get the first and last day of the monthSimpleDateFormat format =NewSimpleDateFormat ("Yyyy-mm-dd"); String FirstDay, Lastday; //get the first day of the previous monthCale =calendar.getinstance (); Cale.add (Calendar.month,0); Cale.set (Calendar.day_of_month,1); FirstDay=Format.format (Cale.gettime ()); //get the last day of the previous monthCale =calendar.getinstance (); Cale.add (Calendar.month,1); Cale.set (Calendar.day_of_month,0); Lastday=Format.format (Cale.gettime ()); System.out.println ("The first and last day of the month are:" + FirstDay + "and" +lastday); //Gets the current date stringDate d =NewDate (); System.out.println ("Current date string 1:" +Format.format (d)); System.out.println ("Current date String 2:" + year + "/" + month + "/" + Day + "" + Hour + ":" + Minute + ":" +second); }}
Java--Get the current date, month of the month, date of month