how to get get time in C# code example
Example 1: c# get time
var timeString = DateTime.Now.ToString("hh:mm:ss");
var time24 = DateTime.Now.ToString("HH:mm:ss");
var timeString = DateTime.Now.ToString("t");
var shortTimeStr = DateTime.Now.ToShortTimeString();
var longTimeStr = DateTime.Now.ToLongTimeString();
var longtimestr = DateTime.Now.ToString("T");
var timeSpan = DateTime.Now.TimeOfDay;
Example 2: get time from datetime c#
DateTime dt = DateTime.Parse("6/22/2009 07:00:00 AM");
dt.ToString("HH:mm");
dt.ToString("hh:mm tt");
dt.ToString("H:mm");
dt.ToString("h:mm tt");