Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7086899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:36:26+00:00 2026-05-28T07:36:26+00:00

How to know how many days has particular month of particular year? String date

  • 0

How to know how many days has particular month of particular year?

String date = "2010-01-19";
String[] ymd = date.split("-");
int year = Integer.parseInt(ymd[0]);
int month = Integer.parseInt(ymd[1]);
int day = Integer.parseInt(ymd[2]);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR,year);
calendar.set(Calendar.MONTH,month);
int daysQty = calendar.getDaysNumber(); // Something like this
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:36:27+00:00Added an answer on May 28, 2026 at 7:36 am

    Java 8 and later

    @Warren M. Nocos.
    If you are trying to use Java 8’s new Date and Time API, you can use java.time.YearMonth class. See Oracle Tutorial.

    // Get the number of days in that month
    YearMonth yearMonthObject = YearMonth.of(1999, 2);
    int daysInMonth = yearMonthObject.lengthOfMonth(); //28  
    

    Test: try a month in a leap year:

    yearMonthObject = YearMonth.of(2000, 2);
    daysInMonth = yearMonthObject.lengthOfMonth(); //29 
    

    Java 7 and earlier

    Create a calendar, set year and month and use getActualMaximum

    int iYear = 1999;
    int iMonth = Calendar.FEBRUARY; // 1 (months begin with 0)
    int iDay = 1;
    
    // Create a calendar object and set year and month
    Calendar mycal = new GregorianCalendar(iYear, iMonth, iDay);
    
    // Get the number of days in that month
    int daysInMonth = mycal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28
    

    Test: try a month in a leap year:

    mycal = new GregorianCalendar(2000, Calendar.FEBRUARY, 1);
    daysInMonth= mycal.getActualMaximum(Calendar.DAY_OF_MONTH);      // 29
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that many threads has been created here & on the internet about
I need to know how many records are in each table in a particular
I know that my question has been answered many times but I still cannot
I know many people ask this but all the answers are specific apps so
I use VIM editor for PHP, i know many people will point to PDT
I need to know how many instances of my process are running on a
I need to know how many <div> elements are in each <li> . So
I dont know how many values will be present from Cell A1 to A65555.
I need to know how many objects of some type exist in my system
I need to know how many replacements are made by Powershell when using either

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.