15

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

44

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,335,956
  • 823
  • 8,931
  • 9,049
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
  • 57,620
  • 8
  • 112
  • 120
18
DateTime d = DateTime.Now;
string s = d.ToString("dd/MM/yyyy");
Console.WriteLine(s);
Gavin Miller
  • 42,055
  • 20
  • 117
  • 184
BFree
  • 100,265
  • 20
  • 154
  • 199