How do you get the current time of day?

How do you get the current time (not date AND time)?

Example: 5:42:12 PM


DateTime.Now.TimeOfDay gives it to you as a TimeSpan (from midnight).

DateTime.Now.ToString("h:mm:ss tt") gives it to you as a string.

DateTime reference: https://msdn.microsoft.com/en-us/library/system.datetime


Try this:

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

For other formats, you can check this site: C# DateTime Format


Another option using String.Format()

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

Current time with AM/PM designator:

DateTime.Now.ToString("hh:mm:ss tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
DateTime.Now.ToString("hh:mm:ss.fff tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)

Current time using 0-23 hour notation:

DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)
DateTime.Now.ToString("HH:mm:ss.fff", System.Globalization.DateTimeFormatInfo.InvariantInfo)

DateTime.Now.TimeOfDay

or

DateTime.Now.ToShortTimeString()