C# – How to get current date in C#


I'm using visual studio 2010 do developt my Windows phone application!
I'm newbie and i don't know how to show current date in follow format

For ex

I use


Out put:

09/04/2012 (this date is my datetime format)

But, I want out put exactly is (date only without "0"):


Best Solution

Well one option is just:

string text = date.Day.ToString();

Or if you still want to use date/time formatting you could use:

string text = string.Format("{0:%d}", date);

Note that here the % is required to specify that you want the d to be a single character custom format string rather than just a standard format string (where d means "short date string").

If you want the rest of your date format, but only want to change how the day of month is represented, you can just change the dd to d:

string text = string.Format("{0:d/MM/yyyy}", date);