Basics: DateTime.ToString() format

One of the most useful overloads of the ToString() method is the ability to provide a format for the object you’re converting to string.

This is of particular interest when dealing with DateTime objects. If, for example, you had a DateTime object as such:

DateTime dNow = DateTime.Now;

and you wanted to display it in the following format:

31 December 1999

you could easily do so, like this:

string sNow = dNow.ToString(“dd MM yyyy”);

MGR: the Intelogist

About MGR: the Intelogist

SharePoint Server developer, turned Sitefinity developer, turned Angular developer, turned SharePoint Online consultant, turned Unily consultant, turned O365 consultant... Never a dull moment!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.