DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") does not account my format

Doctorslo picture Doctorslo · Sep 16, 2013 · Viewed 93.2k times · Source

This is the code I have:

DateTime.Now.AddMinutes(55).ToString("dd/MM/yyyy HH:mm:ss")

The string I get from that code is:

"16.09.2013 19:45:03"

The question is, why the string is not in the format I've provided?

Answer

Kamil Budziewski picture Kamil Budziewski · Sep 16, 2013

Use this:

DateTime.Now.AddMinutes(55).ToString("dd'/'MM'/'yyyy HH:mm:ss")

because / means default date separator, so it's associated with your current culture. So know it will use always / here, no matter of current culture.

Read more here at MSDN