2016-08-03 99 views
-1

我有一个表单,我需要显示单击按钮时的确切时间。当我按下它时,我怎样“捕捉”确切时间(hh:mm:ss)?单击按钮时检测时间

(请,如果问题是重复的,告诉我,让我可以删除这一项)

回答

1

使用DateTime.Now

void myButton_Click(object sender, RoutedEventArgs e) 
{ 
    // Captures the current time in a DateTime object. 
    DateTime currentTime = DateTime.Now; 

    // If you need a string, you can use the ToString method. 
    string timeString = currentTime.ToString("hh:mm:ss"); 
} 
在您的按钮
1

使用DateTime.Now点击处理程序:

protected void btn_Clicked(object sender, EventArgs e) 
{ 
    DateTime whenClicked = DateTime.Now; 
}