W mojej aplikacji konsoli próbuję sformatować do HHmmss
-> Jestem pewien, że jest to spowodowane moimi typami danych, ale jak mogę to zrobić? NULL
, gdy NULL
i nie wyświetlać 1/1/0001 12:00:00 AM
?DateTime To ma wartość NULL, gdy wartością jest DateTime.MinValue lub jej wartość wynosi Null
To moja składnia
public static DateTime fmtLST;
public static string LST = null;
if (LST != null)
{
IFormatProvider format = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;
fmtLST = DateTime.ParseExact(LST, "HHmmss", format);
}
Console.WriteLine(fmtLST.ToString("hh:mm:ss tt"));
Jeśli zmienia się public static DateTime? fmtLastScanTime;
otrzymuję błąd
„Nie przeciążenie dla metody 'ToString' trwa 1 argumenty
Jak mogę czy to wyświetlenie NULL
zamiast 1/1/0001 12:00:00 AM
? Próba rozliczenia za 1/1/0001 12:00:00 AM jest wyświetlana
jeśli 'fmtLST' jest' 'fmtLST.ToString null' następnie()' podniesie wyjątek –
Ale nigdy nie jest null - będzie domyślnie 01.01.01.0000.00:00. Chcę, aby zwrócił wartość NULL, a nie domyślną datę/czas. –