June 28, 2013

[C#]取得本月的第一天及最後一天的日期方法

參考來源:http://www.dotblogs.com.tw/codeman/archive/2011/07/29/32281.aspx 解法一: DateTime FirstDay = new DateTime(DateTime.Now.Year,DateTime.Now.Month,1); DateTime LastDay = new DateTime(DateTime.Now.AddMonths(1).Year,DateTime.Now.AddMonths(1).Month,1).AddDays(-1); 以上解法,是不是更簡短了呢,而且,前言中所提的程式隱含的問題,在此就不會發生了! 解法二: DateTime FirstDay = DateTime.Now.AddDays(-DateTime.Now.Day+1); DateTime LastDay = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.AddMonths(1).Day);

0推薦此文章
Today's Visitors: 0 Total Visitors: 0
Personal Category: Brian的程式筆記 Topic: learning / education / linguistic
[Trackback URL]

Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0