Calculate the week/C # Of the year to obtain the lunar calendar date corresponding to the Gregorian calendar.

Source: Internet
Author: User

One week starts from Sunday
Datetime mdatetime = new datetime (year,); // year is the year required
Int firstweekfirstday = convert. toint32 (mdtime. dayofweek); // the day of the week on the first day of the year
Days = (double) (6-firstweekfirstday );
Datetime secondweekfisrtday = mdtime. adddays (days); Second Monday
Fisrtday = mdatetime. adddays (week * 7); // The first day of week n
Lastday = mdatetime. adddays (week * 7 + 6); // The last day of week n

One week starts from Monday
Datetime mdatetime = new datetime (year,); // year is the year required
Int firstweekfirstday = convert. toint32 (mdtime. dayofweek); // the day of the week on the first day of the year
Days = (double) (7-firstweekfirstday );
Datetime secondweekfisrtday = mdtime. adddays (days); Second Monday
Fisrtday = mdatetime. adddays (week * 7); // The first day of week n
Lastday = mdatetime. adddays (week * 7 + 6); // The last day of week n

Javascript:
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Script language = "JavaScript" type = "text/JavaScript">
Function showdatecount (year, weeknum ){
VaR date = new date (year, 0, (7 * weeknum ));
VaR FD = new date (date. getyear (), (date. getmonth (), (date. getdate ()-date. getday () + 1 ))
VaR Monday = FD. getyear () + "-" + (FD. getmonth () + 1) + "-" + FD. getdate () // the first day of a week
 
VaR LD = new date (date. getyear (), (date. getmonth (), (date. getdate ()-date. getday () + 7 ))
VaR Sunday = lD. getyear () + "-" + (LD. getmonth () + 1) + "-" + LD. getdate () // the last day of the week
Alert (Year + "year" + weeknum + "Week" + Monday + "to" + Sunday)
}
</SCRIPT>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
</Head>

<Body>
<Input type = "text" value = "2007" size = "20" name = "year"> year <input type = "text" name = "weeknum" value = "30 "size =" 20 ">
<Input type = "button" name = "go" value = "click" onclick = "showdatecount (Year. Value, weeknum. Value)">

</Body>
</Html>

C #
// Monthcalendar1 is a calendar control.
System. Globalization. chineselunisolarcalendar c = new chineselunisolarcalendar ();
Private void monthcalendar1_datechanged (Object sender, daterangeeventargs E)
{
Datetime myselectdate = E. end;
Txt_nonglidate.text = string. format (cultureinfo. installeduiculture, "{0}-{1}-{2}", C. getyear (myselectdate), C. getmonth (myselectdate), C. getdayofmonth (myselectdate ));
}

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.