Obtain the number of days in a specified month [c #, js]

Source: Internet
Author: User

C #

1: Get the number of days of the specified month
Int Days = DateTime. DaysInMonth (Year, Month); // Year indicates the Year and Month indicates the Month.
2: Number of days in the current month
Int idate = System. DateTime. DaysInMonth (System. DateTime. Now. Year, System. DateTime. Now. Month );

Js

// Method 1
Function DayNumOfMonth (Year, Month)
{
Var d = new Date (Year, Month, 0 );
Return d. getDate ();
}
// Method 2
Function DayNumOfMonth (Year, Month)
{
Month --;
Var d = new Date (Year, Month, 1 );
D. setDate (d. getDate () + 32-d.getDate ());
Return (32-d.getDate ());
}
// Method 3
Function DayNumOfMonth (Year, Month)
{
Return 32-new Data (year, month, 32). getData ();
}

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.