DateTime: how to display as DD.MM.YYYY?

I have a DateTime variable, and I want to convert it to the string "DD.MM.YYYY" Note that the values โ€‹โ€‹must be separated by a dot.

Of course, I can do a manual string composition. But I am wondering if I can use DateTime.ToString() to perform the required conversion.

+5
source share
4 answers

Yes, you can:

string formatted = dt.ToString("dd'.'MM'.'yyyy");

, / - , , - "." , ':', , , , " ". , "". " " , , . , , , .

, :

string formatted = dt.ToString("dd'.'MM'.'yyyy", CultureInfo.InvariantCulture);

( , "." - .)

+13

, DateTime.ToString :

myDateVariable.ToString("dd.MM.yyyy");

, MM, mm , .

+8

:

DateTime.Now.ToString("d", new CultureInfo("de-DE"))

..

+3

:

date.ToString("dd.MM.yyyy")

. CultureInfo, .

CA1304: CultureInfo, , " :

date.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture)
+2
source

All Articles