C#獲取上個月第一天和最後一天日期的方法
阿新 • • 發佈:2017-12-05
分享 ble bsp 圖片 span margin date 文章 相關
int mouth = DateTime.Now.Month;//當前月
C#獲取上個月第一天和最後一天日期的方法
本文地址: http://www.paobuke.com/develop/c-develop/pbk23311.html
詳談C++引用&和指針在作為形參時的區別為什麽哈希存取比較快?使用它需要付出什麽代價C#在DataTable中根據條件刪除某一行的實現方法
C#DT??IIS??μ?framework°?±?o?μ?·?·¨C#使用iTextSharp從PDF文檔獲取內容的方法C#實現的圖片、string相互轉換類分享C#實現簡單獲取及設置Session類
本文實例講述了C#獲取上個月第一天和最後一天日期的方法。分享給大家供大家參考。
具體實現代碼如下:
代碼如下:
int mouth = DateTime.Now.Month;//當前月
int beforeYear = 0;
int beforeMouth = 0;
if (mouth <= 1)//如果當前月是一月,那麽年份就要減1
{
beforeYear = year – 1;
beforeMouth =12;//上個月
}
else
{
beforeYear = year;
beforeMouth = mouth – 1;//上個月
}
string beforeMouthOneDay = beforeYear + “年” + beforeMouth + “月” + 1 + “日”;//上個月第一天
string beforeMouthLastDay = beforeYear + “年” + beforeMouth + “月” + DateTime.DaysInMonth(year, beforeMouth) + “日”;//上個月最後一天
上個月最後一天也可以這樣寫:
代碼如下:
希望本文所述對大家的C#程序設計有所幫助。
除聲明外,跑步客文章均為原創,轉載請以鏈接形式標明本文地址C#獲取上個月第一天和最後一天日期的方法
本文地址: http://www.paobuke.com/develop/c-develop/pbk23311.html
相關內容
C#利用iTextSharp添加PDF水印C#DT??IIS??μ?framework°?±?o?μ?·?·¨C#使用iTextSharp從PDF文檔獲取內容的方法C#實現的圖片、string相互轉換類分享C#實現簡單獲取及設置Session類
C#獲取上個月第一天和最後一天日期的方法