Answers for "time in c#"

C#
9

c# get time

//Return the time from DateTime object in string format
var timeString = DateTime.Now.ToString("hh:mm:ss");

//Return time in 24h format
var time24 = DateTime.Now.ToString("HH:mm:ss");
  
//Use short time format to return string value
var timeString = DateTime.Now.ToString("t");
var shortTimeStr = DateTime.Now.ToShortTimeString();

//Use long time format
var longTimeStr = DateTime.Now.ToLongTimeString();
var longtimestr = DateTime.Now.ToString("T");

//Return a TimeSpan from midnight
var timeSpan = DateTime.Now.TimeOfDay;
Posted by: Guest on April-01-2020
1

simple time c#

public float timeLeft = 20.0f; //you can change this aswell

void Update()
{
timeLeft -= Time.deltaTime; //you can change this to just removing a number
            if (timeLeft < 0)
            {
            //Method here
            timeLeft += 20.0f; //change this to what you want
            }
}
Posted by: Guest on February-23-2021
0

C# time

//assigns default value 01/01/0001 00:00:00
DateTime dt1 = new DateTime(); 

//assigns year, month, day
DateTime dt2 = new DateTime(2015, 12, 31); 

//assigns year, month, day, hour, min, seconds
DateTime dt3 = new DateTime(2015, 12, 31, 5, 10, 20);
 
//assigns year, month, day, hour, min, seconds, UTC timezone
DateTime dt4 = new DateTime(2015, 12, 31, 5, 10, 20, DateTimeKind.Utc);
Posted by: Guest on May-26-2021

C# Answers by Framework

Browse Popular Code Answers by Language