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
  • 11,875
  • 18
  • 85
  • 108

4 Answers4

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

this gives it to you as a string.

Farhad-Taran
  • 6,282
  • 15
  • 67
  • 121
7

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

Tigran
  • 61,654
  • 8
  • 86
  • 123
6
DateTime.Now.ToShortTimeString().ToString()

This Will give you DateTime as 10:50PM

Kishore Kumar
  • 12,675
  • 27
  • 97
  • 154
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,538
  • 30
  • 50