Java--Get the current date, month of the month, date of month

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.