Date format task in C #

Hi, I am working with a simple C # application to display the system date time.

textbox.Text = DateTime.Now.ToString("MM/dd/yyyy"); 

but it shows the result as: 05-12-2010

What is the problem with this code? or I need to change any place in the regional settings of my car.

Thank you

+6
c # datetime
source share
3 answers

"/" is the locale time and time separator. I suppose that

 DateTime.Now.ToString(@"MM\/dd\/yyyy"); 

will do what you want.

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

+6
source share

You may need to specify the desired culture, as formatting will use the current culture:

 textbox.Text = DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture); 
+3
source share
 DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123); String.Format("{0:MM/dd/yyyy}", dt); // "03/09/2008" 

A source

-one
source share

All Articles