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?
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?
DateTime.Now.ToString("HH:mm:ss tt");
this gives it to you as a string.
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
DateTime.Now.ToShortTimeString().ToString()
This Will give you DateTime as 10:50PM
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?