欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#得到本月有幾周和這幾周的起止時(shí)間示例代碼

 更新時(shí)間:2014年01月16日 10:04:26   作者:  
本篇文章主要是對(duì)c#得到本月有幾周和這幾周的起止時(shí)間的示例代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助

示例代碼:

復(fù)制代碼 代碼如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>無標(biāo)題頁</title>
    <style type="text/css" >
    .hidden{ display:none;}
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
   <script type="text/javascript">

   </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>

        <%

                NumWeeks(new DateTime(2009, 11, 15));

         %>

         <script runat="server" type="text/C#">

             /// <summary>
             /// 獲得本月有幾周
             /// </summary>
             /// <param name="a"></param>
             /// <returns></returns>
             public  void NumWeeks(DateTime dt)
             {
                 //年
                 int year = dt.Year;
                 //月
                 int month = dt.Month;
                 //當(dāng)前月第一天
                 DateTime weekStart = new DateTime(year, month, 1);
                 //該月的最后一天
                 DateTime monEnd = weekStart.AddMonths(1).AddDays(-1);
                 int i = 1;
                 //當(dāng)前月第一天是星期幾
                 int dayOfWeek = Convert.ToInt32(weekStart.DayOfWeek.ToString("d"));
                 //該月第一周結(jié)束日期
                 DateTime weekEnd = dayOfWeek == 0 ? weekStart : weekStart.AddDays(7 - dayOfWeek);

                 richTextBox2.Text += "第" + i + "周起始日期: " + weekStart.ToShortDateString() + "   結(jié)束日期: " + weekEnd.ToShortDateString() + "\n";

                 //當(dāng)日期小于或等于該月的最后一天
                 while (weekEnd.AddDays(1) <= monEnd)
                 {
                     i++;
                     //該周的開始時(shí)間
                     weekStart = weekEnd.AddDays(1);
                     //該周結(jié)束時(shí)間
                     weekEnd = weekEnd.AddDays(7) > monEnd ? monEnd : weekEnd.AddDays(7);

                     richTextBox2.Text += "第" + i + "周起始日期: " + weekStart.ToShortDateString() + "   結(jié)束日期: " + weekEnd.ToShortDateString() + "\n";
                 }

                 richTextBox2.Text += year + "年" + month + "月共有" + i + "周\n";
             }

         </script>
        

            <asp:TextBox ID="richTextBox2" runat="server" TextMode="MultiLine" Height="321px"
                Width="845px" ></asp:TextBox>

        </div>
    </form>
</body>
</html>

相關(guān)文章

最新評(píng)論