SoFunction
Updated on 2025-03-07

c# get sample code for the start and end time of the month for several weeks and these weeks


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">

<html xmlns="http:///1999/xhtml" >
<head runat="server">
<title>Unt title page</title>
    <style type="text/css" >
    .hidden{ display:none;}
    </style>
    <script src="/ajax/libs/jquery/1.4/" type="text/javascript"></script>
   <script type="text/javascript">

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

        <%

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

         %>

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

             /// <summary>
/// How many weeks will it be obtained this month
             /// </summary>
             /// <param name="a"></param>
             /// <returns></returns>
             public  void NumWeeks(DateTime dt)
             {
//Year
                 int year = ;
//moon
                 int month = ;
//The first day of the current month
                 DateTime weekStart = new DateTime(year, month, 1);
//The last day of the month
                 DateTime monEnd = (1).AddDays(-1);
                 int i = 1;
//The first day of the week is the first day of the week
                 int dayOfWeek = Convert.ToInt32(("d"));
//The end date of the first week of the month
                 DateTime weekEnd = dayOfWeek == 0 ? weekStart : (7 - dayOfWeek);

+= "Thread" + i + "Week start date: " + () + "   End date: " + () + "\n";

// When the date is less than or equal to the last day of the month
                 while ((1) <= monEnd)
                 {
                     i++;
//The start time of the week
                     weekStart = (1);
//The end time of the week
                     weekEnd = (7) > monEnd ? monEnd : (7);

+= "Thread" + i + "Week start date: " + () + "   End date: " + () + "\n";
                 }

+= year + "year" + month + "month total" + i + "week\n";
             }

         </script>
        

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

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