Reputation: 3740
Hi I'm working with c# simple application to display system date time.
textbox.Text = DateTime.Now.ToString("MM/dd/yyyy");
but it is showing result as : 05-12-2010
What is the problem with this code? or do I need to change any where in the regional settings of my machine.
thank you
Upvotes: 6
Views: 1453
Reputation: 52185
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
String.Format("{0:MM/dd/yyyy}", dt); // "03/09/2008"
Upvotes: -1
Reputation: 499302
You may need to specify the culture you want, as the formatting will use the current culture:
textbox.Text = DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
Upvotes: 3
Reputation: 1761
the "/" represents the locale datetime seperator. Im guessing that
DateTime.Now.ToString(@"MM\/dd\/yyyy");
will do what you want.
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
Upvotes: 6