Java gets the number of days in the month, the specified number of days, and the specified date for the corresponding week.

Source: Internet
Author: User

1  PackageCom.example.administrator.dayofmonth;2 3 ImportJava.text.SimpleDateFormat;4 ImportJava.util.Calendar;5 Importjava.util.Date;6 7 /**8 * Created by fire dragon naked Mr. on 2017/4/11 0011.9  */Ten  One  Public classNumber_of_days { A  -     /** - * Get the number of days in the month the      */ -      Public Static intGetcurrentmonthday () { -  -Calendar A =calendar.getinstance (); +A.set (Calendar.date, 1); -A.roll (Calendar.date, 1); +         intMaxDate =A.get (calendar.date); A         returnmaxdate; at     } -  -     /** - * The number of days to obtain the corresponding month according to the year and month -      */ -      Public Static intGetdaysbyyearmonth (intYearintmonth) { in  -Calendar A =calendar.getinstance (); to A.set (calendar.year, year); +A.set (Calendar.month, month-1); -A.set (Calendar.date, 1); theA.roll (Calendar.date, 1); *         intMaxDate =A.get (calendar.date); $         returnmaxdate;Panax Notoginseng     } -  the     /** + * Find the day of the week based on the date A      */ the      Public Staticstring Getdayofweekbydate (string date) { +String DayOfweek = "1"; -         Try { $SimpleDateFormat MyFormatter =NewSimpleDateFormat ("Yyyy-mm-dd"); $Date mydate =myformatter.parse (date); -SimpleDateFormat formatter =NewSimpleDateFormat ("E"); -String str =Formatter.format (mydate); theDayOfweek =str; - Wuyi}Catch(Exception e) { theSYSTEM.OUT.PRINTLN ("Error!")); -         } Wu         returnDayOfweek; -     } About  $}

Java gets the number of days in the month, the specified number of days, and the specified date for the corresponding week.

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.