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: simple time c#
public float timeLeft = 20.0f;
void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft < 0)
{
timeLeft += 20.0f;
}
}
Example 3: C# time
DateTime dt1 = new DateTime();
DateTime dt2 = new DateTime(2015, 12, 31);
DateTime dt3 = new DateTime(2015, 12, 31, 5, 10, 20);
DateTime dt4 = new DateTime(2015, 12, 31, 5, 10, 20, DateTimeKind.Utc);