Reputation: 2759
How can I convert my DateTime
object to this kind of date format:
I am currently doing object.GetDateTimeFormats('D')[1].ToString()
This is giving me January 31, 2012. But I should be able to get these two things:
Upvotes: 7
Views: 40945
Reputation: 195
To get the Format like - September 26, 2019
string.Format("{0:MMMM dd, yyyy}", YourDate);
Upvotes: 1
Reputation: 691
Console.WriteLine(DateTime.Now.ToString("d-MMM-yy"));
18-Jan-18
Console.WriteLine(DateTime.Now.ToString("d-MM-yy"));
18-1-18
Console.WriteLine(DateTime.Now.ToString("d-MM-yyyy"));
18-1-2018
MoreDetails :- http://www.code-sample.net/CSharp/Format-DateTime
Upvotes: 1
Reputation: 180788
Use a custom DateTime
formatting string:
// Returns Jan 31, 2012
myDateTimeObject.ToString("MMM dd, yyyy");
// Returns 31 January, 2012
myDateTimeObject.ToString("dd MMMM, yyyy");
All of the custom date/time formats are listed here.
Upvotes: 18
Reputation: 1483
All types of date formatting you need.
Just select the correct string format you need:
Upvotes: 3