How is String.Format the day of the month in C #?

Formatting DateTime has some match between the standard date and time formatting strings and some of them with a custom format specifier. As a result, when I evaluate this expression:

string.Format(">{0:d}< >{0: d}<", DateTime.Now) 

and get this result:

>8/3/2009< > 3<

My question is: how do I get String.Format to output only the day of the month (using the d format) without any surrounding spaces?

+4
source share
4 answers

use "{0:%d} ": link

+10
source

I keep this page in my favorites ...

http://blog.stevex.net/index.php/string-formatting-in-csharp/

Saves me all the time.

+2
source

Try:

 DateTime.Now.Day.ToString() 
0
source

DateTime.Now.ToString ("dd");

0
source

All Articles