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.
DateTime.ToString()
Yes, you can:
string formatted = dt.ToString("dd'.'MM'.'yyyy");
, / - , , - "." , ':', , , , " ". , "". " " , , . , , , .
, :
string formatted = dt.ToString("dd'.'MM'.'yyyy", CultureInfo.InvariantCulture);
( , "." - .)
, DateTime.ToString :
myDateVariable.ToString("dd.MM.yyyy");
, MM, mm , .
:
DateTime.Now.ToString("d", new CultureInfo("de-DE"))
..
.
date.ToString("dd.MM.yyyy")
. CultureInfo, .
CultureInfo
CA1304: CultureInfo, , " :
date.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture)