C # Date Time Formatting

How to convert a DateTime object to this date format:

  • Mmm dd yyyy
  • dd month yyyy

I am currently doing object.GetDateTimeFormats ('D') [1] .ToString ()

This gives me January 31, 2012. But I should be able to get these two things:

  • January 31, 2012
  • January 31, 2012
+6
source share
4 answers

Use the custom DateTime formatting string:

 // Returns Jan 31, 2012 myDateTimeObject.ToString("MMM dd, yyyy"); // Returns 31 January, 2012 myDateTimeObject.ToString("dd MMMM, yyyy"); 

All custom date and time formats are listed here.

+17
source

All types of date formatting you need.

Just select the desired line format:

  • MMM - gives you Jan, Feb, Mar
  • MMMM - gives you January, February, March.
+3
source
 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

Additional Information : - http://www.code-sample.net/CSharp/Format-DateTime

+1
source

To get the format as - September 26, 2019

 string.Format("{0:MMMM dd, yyyy}", YourDate); 
+1
source

Source: https://habr.com/ru/post/1393890/


All Articles