C# get the last day and last day of the month


 

/// <summary> ///  Get the first day of a month /// </summary> /// <param name="datetime"> To get the time of the first day of the month </param> /// < returns></returns> 
        

        
 
        
 
        
 

         Private  the DateTime FirstDayOfMonth (the DateTime datetime)
        
{ return  datetime.AddDays ( . 1 -  datetime.Day);         } /// <Summary> ///  acquired last day of a month /// </ Summary> /// <param name = "datetime"> To get the time of the last day of the month </param> /// <returns></returns>
            
 


        
 
        

        
 
        
 
        
 

         Private  the DateTime LastDayOfMonth (the DateTime datetime)
        
{ return  datetime.AddDays ( . 1 -  datetime.Day) .AddMonths ( . 1 ) .AddDays ( - . 1 );         } /// <Summary> ///  acquires the first day of the last month @ / </summary> /// <param name="datetime"> To get the current time of the first day of the previous month </param> /// <returns></returns>
            
 


        
 
        

        
 
        
 
        
 

         Private  the DateTime FirstDayOfPreviousMonth (the DateTime datetime)
        
{ return  datetime.AddDays ( . 1 -  datetime.Day) .AddMonths ( - . 1 );         } /// <Summary> ///  acquired last day of the last month /// </ Summary> /// <param name="datetime"> To get the current time of the last day of the previous month </param> /// <returns></returns>
            
 


        
 
        

        
 
        
 
        
 

         private  DateTime LastDayOfPrdviousMonth(DateTime datetime)
        
{
            
return datetime.AddDays(1 - datetime.Day).AddDays(-1);
        }


 Server time  on the first day of last month ().AddMonths(-1).AddDays(1-Server time().Day).ToString("yyyy-MM-dd 00:00:00");  Server time on the

end of last month
() .AddDays(1-server time() .Day).AddDays(-1).ToString("yyyy-MM-dd 23:59:59");


Guess you like

Origin blog.csdn.net/wangshengfeng1986211/article/details/6599713