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:
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.
All types of date formatting you need.
Just select the correct string format you need:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.