jestges
jestges

Reputation: 3740

Date time format problem in c#

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

Answers (3)

npinti
npinti

Reputation: 52185

DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"

Source

Upvotes: -1

Oded
Oded

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

hhravn
hhravn

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

Related Questions