2012-05-15 24 views

Respuesta

12
if (t1.HasValue) 
    string st1 = t1.Value.ToString(format); 
+0

http: // stack overflow.com/questions/1833054/how-can-i-format-a-nullable-datetime-with-tostring My Bad. Cerrar/eliminar, por favor. Lo siento – VoonArt

1

puede probar de esta manera, el tipo nullabale tiene la propiedad llamada HasValue Nullable has Value

if (t1.HasValue) 
    t1.Value.ToString(yourFormat) 
3

Uso Coalesce operador

DateTime? t1 = ...; 

string st1 = t1 ?? t1.Value.ToString(format); 
0

Usted debe comprobar primero si DateTime es nulo o no

string strDate = (st1 != null ? st1.Value.ToString(format) : "n/a");