18

I need to get the current time in C# but when I create a DateTime object, the time is set to 00:00:00.

How can I get the current instance of time?

peterh
  • 1
  • 15
  • 76
  • 99

4 Answers4

40
DateTime.Now.ToString("HH:mm:ss tt");

this gives it to you as a string.

Farhad-Taran
  • 5,840
  • 13
  • 60
  • 113
7

DateTime.Now is what you're searching for...

Tigran
  • 60,656
  • 8
  • 83
  • 120
6
DateTime.Now.ToShortTimeString().ToString()

This Will give you DateTime as 10:50PM

Kishore Kumar
  • 12,319
  • 27
  • 91
  • 151
5

try this:

 string.Format("{0:HH:mm:ss tt}", DateTime.Now);

for further details you can check it out : How do you get the current time of day?

Community
  • 1
  • 1
Jignesh Rajput
  • 3,520
  • 26
  • 50