Answers for "how to get date 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
2

c# get date

DateTime.Now.ToString("dd/MM/yyyy");
Posted by: Guest on March-16-2021
9

c# get current date

DateTime now = DateTime.Now;
Posted by: Guest on April-25-2020
3

c# get today's date

DateTime today = DateTime.Today;
Posted by: Guest on March-25-2020

C# Answers by Framework

Browse Popular Code Answers by Language