以下代码显示上个月的最后一天。
MonthCalendar1.SelectionEnd = MonthCalendar1.SelectionStart.AddDays(-MonthCalendar1.SelectionStart.Day)
哪个代码给出了YearCalendar1选定年份的第一天?
因此,如果选择日期是例如13.06.2015如何获得01.01.2015?
答案 0 :(得分:2)
只使用参考日期的年份创建一个新日期,例如:
Dim firstOfYearDate As Date = New Date(baseDate.Year, 1, 1)
喜欢这个
MonthCalendar1.MaxSelectionCount = 365
MonthCalendar1.SelectionEnd = New Date(2015, 06, 13)
MonthCalendar1.SelectionStart = New Date(MonthCalendar1.SelectionEnd.Year, 1, 1)
答案 1 :(得分:0)
如果您想使用当前添加负数天数的方法,只需从DateTime.DayOfYear中减去一个:
MonthCalendar1.SelectionEnd = MonthCalendar1.SelectionStart.AddDays(-(MonthCalendar1.SelectionStart.DayOfYear-1))
如果您想要所选年份的最后一天,请使用DateTime.DaysInMonth():
Dim dt As New DateTime(MonthCalendar1.SelectionStart.Year, 12, DateTime.DaysInMonth(MonthCalendar1.SelectionStart.Year, 12))