更新时间:2023-02-14 18:11:35
p>您要使用 DateTime.ToString(format)
不是 Nullable< DateTime> .ToString(无重载)
:
You want to use DateTime.ToString(format)
not Nullable<DateTime>.ToString(no overload)
:
DateTime? myDate = form.dteStartDate;
string sqlFormattedDate = myDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
当然这并不处理没有价值的情况,也许是这样的:
Of course this doesn't handle the case that there is no value. Perhaps something like this:
string sqlFormattedDate = myDate.HasValue
? myDate.Value.ToString("yyyy-MM-dd HH:mm:ss")
: "<not available>";