19

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?

2

4 Answers 4

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

this gives it to you as a string.

1
  • 9
    For date and time use DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
    – Eun
    Commented Aug 7, 2013 at 9:10
7

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

6
DateTime.Now.ToShortTimeString().ToString()

This Will give you DateTime as 10:50PM

0
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?