Java gets the number of days in the month, the number of days specified, and the specified date for the corresponding week (RPM)

Source: Internet
Author: User

 Java gets the number of days in the month, the specified number of days, and the specified date for the corresponding weekCategory: Java2012-12-25 23:52 3201 People read comments (0) favorite reports J2sej2sejavajavajava gets the number of days in the month gets a specified number of days gets the week of the specified date
Package Com;import java.text.simpledateformat;import java.util.calendar;import java.util.date;/** * @author Gerrard * * public class Testgetweek {public static void main (string[] args) {int currentmaxdays = Getcurrentmonthday (); int Maxdaysbyd ate = Getdaysbyyearmonth (2012, 11); String week = getdayofweekbydate ("2012-12-25"); System.out.println ("Days of the Month:" + currentmaxdays); System.out.println ("November 2012 days:" + maxdaysbydate); System.out.println ("2012-12-25 is:" + week);} /** * Gets the number of days in the month * */public static int getcurrentmonthday () {Calendar a = Calendar.getinstance (); A.set (calendar.date, 1); A.R Oll (Calendar.date,-1); int maxdate = A.get (calendar.date); return maxdate;} /** * Gets the corresponding month days based on year of year * */public static int getdaysbyyearmonth (int year, int month) {Calendar a = calendar.getinstance (); A.set (Calendar.year, year); A.set (Calendar.month, month-1); A.set (calendar.date, 1); A.roll (Calendar.date,-1); int MaxDate = A.get (calendar.date); return maxdate;} /** * Find the day of the week based on the date */public static String GetdayofweekbydaTe (string date) {string dayOfweek = "1"; try {simpledateformat myformatter = new SimpleDateFormat ("YYYY-MM-DD");D ate Myda      Te = myformatter.parse (date);      SimpleDateFormat formatter = new SimpleDateFormat ("E");      String str = Formatter.format (mydate);      DayOfweek = str; } catch (Exception e) {System.out.println ("Error!");} return dayOfweek;}}

Java gets the number of days in the month, the number of days specified, and the specified date for the corresponding week (RPM)

Related Article

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.