16

Possible Duplicates:
Convert a string to a date in .net
format date in c#
What markup is used to format StackOverflow questions?

How to convert DateTime object to dd/mm/yyyy in C#?

Community
  • 1
  • 1

3 Answers3

45

One thing to note in addition to the other answers - / is a format character itself, representing the local date separator. If you want to make absolutely sure it uses an actual slash, either use the invariant culture (which uses a slash):

string s = dateTime.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);

or escape the slashes:

string s = dateTime.ToString("dd'/'MM'/'yyyy");
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
33

Are you talking about converting to a string for printing or something?

String s = DateTime.ToString("dd/MM/yyyy");

And to be complete, here is more information about DateTime.ToString and DateTime formatting in general.

Welbog
  • 59,154
  • 9
  • 110
  • 123
18
DateTime d = DateTime.Now;
string s = d.ToString("dd/MM/yyyy");
Console.WriteLine(s);
Gavin Miller
  • 43,168
  • 21
  • 122
  • 188
BFree
  • 102,548
  • 21
  • 159
  • 201