Answers for "c# get datetime now"

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
9

c# get current date

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

c# datetime current

DateTime now = DateTime.Now;
string strDate = now.ToString("YYYY-MM-dd");
Posted by: Guest on January-21-2021
1

date time heutiges datum

var date= DateTime.Now.Date;
Posted by: Guest on April-10-2020
1

get time from datetime c#

DateTime dt = DateTime.Parse("6/22/2009 07:00:00 AM");

dt.ToString("HH:mm"); // 07:00 // 24 hour clock // hour is always 2 digits
dt.ToString("hh:mm tt"); // 07:00 AM // 12 hour clock // hour is always 2 digits
dt.ToString("H:mm"); // 7:00 // 24 hour clock
dt.ToString("h:mm tt"); // 7:00 AM // 12 hour clock
Posted by: Guest on July-09-2020
0

date time heutiges datum

string x = DateTime.Now.ToShortDateString()
Posted by: Guest on April-10-2020

C# Answers by Framework

Browse Popular Code Answers by Language