-1

I have a form which I need to show the exact time when my button was clicked. How may I "capture" the exact time (hh:mm:ss) when I pressed it?

(please, if the question is duplicated, inform me so I can delete this one)

MattDAVM
  • 475
  • 2
  • 6
  • 23

2 Answers2

2

Use 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");
}
Sumner Evans
  • 8,551
  • 5
  • 29
  • 46
2

Use DateTime.Now in your button clicked handler:

protected void btn_Clicked(object sender, EventArgs e)
{
    DateTime whenClicked = DateTime.Now;
}
itsme86
  • 18,916
  • 4
  • 39
  • 54