我想让日历显示特定的月份,我想在日历中定义允许的日期范围
DateTime today = DateTime.Today;
DatePickerDialog dateDialog = new DatePickerDialog(this, this.OnToDateSet, today.Year, today.Month - 1, today.Day);
dateDialog.DatePicker.MaxDate = DateTime.Today.Millisecond;
dateDialog.DatePicker.MinDate = new DateTime(today.Year, today.Month - 2, today.Day).Millisecond;
dateDialog.Show();
这就是我得到的回报......它出现时显示错误的年份和月份
如果我注释掉 maxdate 和 mindate 那么日历会在正确的年份和月份打开
有人请澄清
这就是我得到的回报......它出现时显示错误的年份和月份
如果我注释掉 maxdate 和 mindate 那么日历会在正确的年份和月份打开
如果你调试你的代码,你会发现DateTime.Today.Millisecond
并new DateTime(today.Year, today.Month - 2, today.Day).Millisecond
返回 0。这就是出错的地方。在 Xamarin 中,如果要获取毫秒,则需要做一个 DateTime 偏移量:
DateTime today = DateTime.Today;
DatePickerDialog dateDialog = new DatePickerDialog(this, this, today.Year, today.Month - 1, today.Day);
//DateTime.MinValue isn't 1970/01/01 so we need to create a min date manually
double maxSeconds = (DateTime.Today - new DateTime(1970, 1, 1)).TotalMilliseconds;
double minSeconds = (new DateTime(today.Year, today.Month - 2, today.Day) - new DateTime(1970, 1, 1)).TotalMilliseconds;
dateDialog.DatePicker.MaxDate = (long)maxSeconds;
dateDialog.DatePicker.MinDate = (long)minSeconds;
dateDialog.Show();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句