計算一年中的第幾周/c#得到陽曆對應農曆日期

來源:互聯網
上載者:User

  一周從周日算起  
  DateTime   mDatetime=new   DateTime(year,1,1);//year為要求的那一年  
  int   firstweekfirstday=Convert.ToInt32(mDTime.DayOfWeek);//一年中第一天是周幾  
  days=(double)(6-firstweekfirstday);  
  DateTime   secondweekfisrtday=mDTime.AddDays(days);第二周一  
  fisrtday=MDatetime.AddDays(week*7);//第N周第一天  
  lastday=MDatetime.AddDays(week*7+6);//第N周最後一天  
   
  一周從周一算起  
  DateTime   mDatetime=new   DateTime(year,1,1);//year為要求的那一年  
  int   firstweekfirstday=Convert.ToInt32(mDTime.DayOfWeek);//一年中第一天是周幾  
  days=(double)(7-firstweekfirstday);  
  DateTime   secondweekfisrtday=mDTime.AddDays(days);第二周一  
  fisrtday=MDatetime.AddDays(week*7);//第N周第一天  
  lastday=MDatetime.AddDays(week*7+6);//第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()//一周的第一天
 
 var LD=new Date(date.getYear(),(date.getMonth()),(date.getDate()-date.getDay()+7))
 var Sunday=LD.getYear()+"-"+(LD.getMonth()+1)+"-"+LD.getDate() //一周的最後一天
 alert(year+"年第"+weekNum+"周是"+Monday+"至"+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">年<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是日曆控制項
 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));
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.