在我的控制台应用程序中,我正在尝试格式化为HHmmss- >我确信这是由于我的数据类型,但我怎么能在NULL何时NULL显示1/1/0001 12:00:00 AM?
这是我的语法
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"));
Run Code Online (Sandbox Code Playgroud)
如果改为public static DateTime? fmtLastScanTime;我得到错误
'方法'ToString'没有重载需要1个参数
我怎么能有这个显示NULL而不是1/1/0001 12:00:00 AM?试图计算显示的1/1/0001 12:00:00 AM
可能是但试试这个
IFormatProvider format = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;
fmtLST = DateTime.ParseExact((LST != null ? LST : null), "HHmmss", format);
Run Code Online (Sandbox Code Playgroud)