0

我正在尝试将 mindate 设置为 1900 并将 maxdate 设置为 1997 到 DatePickerDialog。但无论我尝试什么,对话框上的结果都不是应该的。文档说它应该是自 1970 年以来的毫秒数。所以这段代码应该可以工作。

我错过了什么?

var dialog = new DatePickerDialog(this, (ss, ee) =>
{
  var dateSelected = ee.Date;
}, model.Birthday.Year, model.Birthday.Month - 1, model.Birthday.Day);


var origin = new DateTime(1970, 1, 1);
dialog.DatePicker.MinDate = 0;// (int)(DateTime.Now.Date.AddYears(-120) - origin).TotalMilliseconds;
dialog.DatePicker.MaxDate = (int)(DateTime.Now.Date.AddYears(-8) - origin).TotalMilliseconds;
4

2 回答 2

3

问题是超过了可以容纳TotalMilliseconds的最大值。int

因此,将其转换为long就可以了,这实际上是DatePicker.MaxDate 预期的。

dialog.DatePicker.MaxDate = (long)(DateTime.Now.Date.AddYears(-8) - origin).TotalMilliseconds;
于 2013-02-27T01:58:10.873 回答
1
  protected override Dialog OnCreateDialog(int id)
        {
            switch (id)
            {
                case DATE_DIALOG_ID:
                    DatePickerDialog dialog = new DatePickerDialog(this, OnDateSet, date.Year, date.Month - 1, date.Day);
                    string _gs = servis.gosterilecekRandevuGunSuresi();
                    int _guns = Convert.ToInt32(_gs);



                    DateTime origin = new DateTime(1970, 1, 1);
                    string tarih = origin.Date.ToString("dd.MM.yyyy");
                    DateTime dt = Convert.ToDateTime(tarih);
                    var datetime = Convert.ToDateTime(tarih);

                    long sayi = (long)(DateTime.Now.Date - origin.Date).TotalMilliseconds;
                    long sayi2 = (long)(DateTime.Now.Date.AddDays(_guns) - origin).TotalMilliseconds;
                    dialog.DatePicker.MinDate = sayi;
                    dialog.DatePicker.MaxDate = sayi2;

                    return dialog;
            }
            return null;
        }
于 2014-08-15T08:02:49.153 回答