【问题标题】:Detect time when button was clicked [duplicate]检测单击按钮的时间[重复]
【发布时间】:2016-08-03 23:12:15
【问题描述】:

我有一个表单,我需要显示我的按钮被点击的确切时间。当我按下它时,我如何“捕获”确切的时间(hh:mm:ss)?

(请,如果问题重复,请通知我,以便我删除此问题)

【问题讨论】:

    标签: c# winforms datetime button


    【解决方案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");
    }
    

    【讨论】:

      【解决方案2】:

      在您的按钮单击处理程序中使用DateTime.Now

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

      【讨论】:

        猜你喜欢
        • 2012-10-16
        • 2019-12-23
        • 2011-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多