How to Convert long date to short date in C#
By FoxLearn 11/10/2024 2:41:55 AM 77
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
- How to get application folder path in C#
- How to copy data to clipboard in C#
- How to mark a method as obsolete or deprecated in C#
- How to Call the Base Constructor in C#
- Deep Copy of Object in C#
- How to Catch Multiple Exceptions in C#
- How to cast int to enum in C#
- What is the difference between String and string in C#?
Categories
Popular Posts
SB Admin Template
11/17/2024
RuangAdmin Template
11/17/2024
DASHMIN Admin Dashboard Template
11/17/2024
K-WD Tailwind CSS Admin Dashboard Template
11/17/2024