我有这段代码,当执行时给我74天,这是正确的,但oldDate
的日期必须来自TextBox
。有谁知道如何做到这一点,DateTime
只需要三个整数。使用DateTime从textbox.text输入
private void myButton_Click(object sender, RoutedEventArgs e)
{
string myDate = myTextBox.Text;
DateTime oldDate = new DateTime(2013, 6, 5);
DateTime newDate = DateTime.Now;
// Difference in days, hours, and minutes.
TimeSpan ts = oldDate - newDate;
// Difference in days.
int differenceInDays = ts.Days;
differenceInDays = ts.Days;
myTextBlock.Text = differenceInDays.ToString();
}
正进入文本框的日期用户?如果是这样,你可以使用'oldDate = DateTime.Parse(myTextBox.Text)'。 – 2013-03-22 16:48:00
同意..或者如果你想他们有单独的领域,并在一起.. eack文本框可以MonthTextBox.Text = Convert.ToInt32(stringvalue) – gcoleman0828 2013-03-22 16:50:41
感谢您的时间马丁现在工作正常。 – user640707 2013-03-22 16:56:29