string.format e separatore date

Oggi ho scoperto che lo string.format utilizzato con le date come ad esempio:

string.Format("0:dd/MM/yyyy", myDateTime);

è dipendente dalla culture corrente, in particolare il separatore è dipendente da tale impostazione. Quindi in culture tedesca la data verrà stampata nel formato dd.MM.yyyy dato che il separatore è il punto.

Per ottenere come separatore lo slash occorre usare:

string.Format("0:dd'/'MM'/'yyyy", myDateTime);

Technorati tags:

Print | posted @ giovedì 10 gennaio 2013 21:39

Comments on this entry:

Gravatar # re: string.format e separatore date
by Massimo at 11/01/2013 11:20

Ciao Emanuele, si può ottenere il separatore
con le / anche usando System.IFormatProvider
Gravatar # re: string.format e separatore date
by Emanuele Prato at 13/01/2013 19:29

Programmo da un po' ma l'articolo che hai indicato è veramente interessante.
Comments have been closed on this topic.