获取当前月的最后一天:2010-11-30 00:00:00
9 个解决方案
#1
去SQL论坛发贴去问问
#2
int year = DateTime.Now.Year;
int month = DateTime.Now.Month;
DateTime firstDayOfThisMonth = new DateTime(year, month, 1);
DateTime lastDayOfThisMonth = new DateTime(year, month, DateTime.DaysInMonth(year, month));
int month = DateTime.Now.Month;
DateTime firstDayOfThisMonth = new DateTime(year, month, 1);
DateTime lastDayOfThisMonth = new DateTime(year, month, DateTime.DaysInMonth(year, month));
#3
#4
晕,我想要的是用C#得到的,去SQL区有神马用?
#5
DateTime dtFirstDay = DateTime.Parse(dt.ToString("yyyy-MM-dd").Substring(0, 8) + "01");
#6
void Main()
{
DateTime first=new DateTime(DateTime.Now.Year,DateTime.Now.Month,1);
DateTime last=first.AddMonths(1).AddDays(-1);
Console.WriteLine(first.ToString("yyyy-MM-dd"));
Console.WriteLine(last.ToString("yyyy-MM-dd"));
}
//2010-11-01
//2010-11-30
#7
获取当前月的最后一天的逻辑是:
下个月的第一天减去1天 就是当前月的最后一天
下个月的第一天减去1天 就是当前月的最后一天
#8
DateTime dt = DateTime.Now;
DateTime dt1 = new DateTime(dt.Year,dt.Month,1);
DateTime dt2 = dt1.AddMonths(1).AddDays(-1);
DateTime dt1 = new DateTime(dt.Year,dt.Month,1);
DateTime dt2 = dt1.AddMonths(1).AddDays(-1);
#1
去SQL论坛发贴去问问
#2
int year = DateTime.Now.Year;
int month = DateTime.Now.Month;
DateTime firstDayOfThisMonth = new DateTime(year, month, 1);
DateTime lastDayOfThisMonth = new DateTime(year, month, DateTime.DaysInMonth(year, month));
int month = DateTime.Now.Month;
DateTime firstDayOfThisMonth = new DateTime(year, month, 1);
DateTime lastDayOfThisMonth = new DateTime(year, month, DateTime.DaysInMonth(year, month));
#3
#4
晕,我想要的是用C#得到的,去SQL区有神马用?
#5
DateTime dtFirstDay = DateTime.Parse(dt.ToString("yyyy-MM-dd").Substring(0, 8) + "01");
#6
void Main()
{
DateTime first=new DateTime(DateTime.Now.Year,DateTime.Now.Month,1);
DateTime last=first.AddMonths(1).AddDays(-1);
Console.WriteLine(first.ToString("yyyy-MM-dd"));
Console.WriteLine(last.ToString("yyyy-MM-dd"));
}
//2010-11-01
//2010-11-30
#7
获取当前月的最后一天的逻辑是:
下个月的第一天减去1天 就是当前月的最后一天
下个月的第一天减去1天 就是当前月的最后一天
#8
DateTime dt = DateTime.Now;
DateTime dt1 = new DateTime(dt.Year,dt.Month,1);
DateTime dt2 = dt1.AddMonths(1).AddDays(-1);
DateTime dt1 = new DateTime(dt.Year,dt.Month,1);
DateTime dt2 = dt1.AddMonths(1).AddDays(-1);