How can I convert the nullable DateTime dt2 to a formatted string?
DateTime dt = DateTime.Now;
Console.WriteLine(dt.ToString(\"yyyy-MM-dd hh
Simple generic extensions
public static class Extensions
{
///
/// Generic method for format nullable values
///
/// Formated value or defaultValue
public static string ToString(this Nullable nullable, string format, string defaultValue = null) where T : struct
{
if (nullable.HasValue)
{
return String.Format("{0:" + format + "}", nullable.Value);
}
return defaultValue;
}
}