C # The function of the day of the week based on the month _c# tutorial

Source: Internet
Author: User

DateTime.Now.ToString ("dddd", New System.Globalization.CultureInfo ("ZH-CN"));

Today on the Internet to see some of the implementation of C # on the basis of the day of the week to calculate the introduction:

The algorithm is as follows:
Kimlarsson Calculation formula
w= (d+2*m+3* (m+1)/5+y+y/4-y/100+y/400) MoD 7
in the formula D represents the number of days in the date, m represents the number of months, and Y represents the number of years.
Note: There is a different formula in the formula:
Consider January and February as the January or March and January or April of the previous year, for example: if it is 2004-1-10, convert it to: 2003-13-10 to substitute the formula.
The code is as follows:

 Y-year, M-month, D-Date 

string caculateweekday (int y,int m,int d)
  {
    string[] weekstr ={"Day", "one", "two", "three", "four", "Five", " VI "};

    if (M < 3)
    {
      m + =;
      if (y% = = 0 | | y%!= 0 && y% 4 = 0)
      {
        d--
      }
    } else
    {
      d = 1;
    }
    Return "Week" + weekstr[(d + 2 * m + 3 * (M + 1)/5 + y + Y/4-y/100 + y/400)% 7]; 
    

  

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.