DateTime date = DateTime.Today; string shortDateString = date.ToShortDateString(); Console.WriteLine(shortDateString);
string dateString = "2021-08-01"; DateTime date = DateTime.ParseExact(dateString, "yyyy-MM-dd", CultureInfo.InvariantCulture); string shortDateString = date.ToShortDateString(); Console.WriteLine(shortDateString);In this example, we create a string with a date value in a specific format. Then we use the DateTime.ParseExact method to create a new DateTime instance from this string. Finally, we use the ToShortDateString method to convert this date to its short date string representation and print the result. Possible package library for System.DateTime class: System.Runtime.dll.