How to Convert long date to short date in C#
By FoxLearn 11/10/2024 2:41:55 AM 113
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 handle nulls with SqlDataReader in C#
- Resolve nullable warnings
- Cannot convert null to type parameter ‘T’
- How to create a custom exception in C#
- How to check if a nullable bool is true in C#
- How to make a file read-only in C#
- How to Get all files in a folder in C#
- How to validate an IP address in C#
Categories
Popular Posts
How to disable Windows Defender SmartScreen
12/24/2024
Improve Blazor Website Performance
12/19/2024