How to Convert long date to short date in C#
By FoxLearn 11/10/2024 2:41:55 AM 2
In C#, you can convert a long date string (e.g., "Monday, October 10, 2024") to a short date string (e.g., "10/10/2024") using the DateTime class and its formatting capabilities.
To convert a long date string to a short date string in C#, one simple approach is convert the long date string into a DateTime
object and then get short date string from it.
string longDate = DateTime.Now.ToLongDateString(); Console.WriteLine(longDate); //Sunday, November 10, 2024 DateTime dt = Convert.ToDateTime(longDate); string shortDate = dt.ToShortDateString(); Console.WriteLine(shortDate); //11/10/2024
Categories
Popular Posts
How to create excel file in c# using dataset
11/05/2024
How to secure ASP.NET Core with NWebSec
11/07/2024
How to download redis for Windows
10/29/2024