DateTime - 求本月月末,本月月初,本周周日,本周周一,本季度末,本年年初,本年年末
Dim dt As DateTime = DateTime.Now
'当前时间
Dim startWeek As DateTime = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d")))
'本周周一
Dim endWeek As DateTime = startWeek.AddDays(6)
'本周周日
Dim startMonth As DateTime = dt.AddDays(1 - dt.Day)
'本月月初
Dim endMonth As DateTime = startMonth.AddMonths(1).AddDays(-1)
'本月月末
'DateTime endMonth = startMonth.AddDays((dt.AddMonths(1) - dt).Days - 1); '本月月末
Dim startQuarter As DateTime = dt.AddMonths(0 - (dt.Month - 1) Mod 3).AddDays(1 - dt.Day)
'本季度初
Dim endQuarter As DateTime = startQuarter.AddMonths(3).AddDays(-1)
'本季度末
Dim startYear As New DateTime(dt.Year, 1, 1)
'本年年初
Dim endYear As New DateTime(dt.Year, 12, 31)
'本年年末
'当前时间
Dim startWeek As DateTime = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d")))
'本周周一
Dim endWeek As DateTime = startWeek.AddDays(6)
'本周周日
Dim startMonth As DateTime = dt.AddDays(1 - dt.Day)
'本月月初
Dim endMonth As DateTime = startMonth.AddMonths(1).AddDays(-1)
'本月月末
'DateTime endMonth = startMonth.AddDays((dt.AddMonths(1) - dt).Days - 1); '本月月末
Dim startQuarter As DateTime = dt.AddMonths(0 - (dt.Month - 1) Mod 3).AddDays(1 - dt.Day)
'本季度初
Dim endQuarter As DateTime = startQuarter.AddMonths(3).AddDays(-1)
'本季度末
Dim startYear As New DateTime(dt.Year, 1, 1)
'本年年初
Dim endYear As New DateTime(dt.Year, 12, 31)
'本年年末
![]() | 本作品采用 知识共享署名-非商业性使用 2.5 中国大陆许可协议进行许可。 |