C# how to get current time 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: c# datetime current
DateTime now = DateTime.Now;
string strDate = now.ToString("YYYY-MM-dd");