0
我一直在試圖弄清楚如何使兩個值匹配,並無濟於事,每次都得到不匹配的時間。當使用此代碼時,我來得非常接近:如何正確比較DateTime.Now和DateTimePicker.Value並匹配兩個值?
this.dateOfBirthPicker.Value = DateTime.Now;
但它在匹配彼此的值時已經秒了一秒鐘。我環顧四周,注意到經常彈出日期,但它說我缺少一個程序集引用,是否使用System.DateTime?因爲我補充說,仍然沒有工作。我不知道還有什麼可以嘗試,並偷偷摸摸的幫助。當我嘗試更改時間或刪除時間並僅使用僅限日期格式時,DateTimePicker會很痛苦。
如果用戶沒有更改或設置DateOfBirthPicker設置爲DateTime.Now(默認),那麼用戶將被要求這樣做,這就是我想要做的。
C#代碼:
DateTime dtN = DateTime.Now; // create and initialize DateTime.Now
this.dateOfBirthPicker.Value = DateTime.Now; // set current time for DateTimePicker to match dtN
DateTime date = dateOfBirthPicker.Value.Date; // ERROR: missing directive or assembly reference
if(dateOfBirthPicker.Value == dtN)
{
dateOfBirthTBL.Text = "Date of Birth: *";
dateOfBirthTBL.Foreground = new SolidColorBrush(Colors.Red);
dateOfBirthTBL.FontWeight = FontWeights.Bold;
}
謝謝!我現在明白了! – TheAmazingKnight