更新时间:2023-02-14 18:15:31
您想使用 DateTime.ToString(format)
不是 Nullable
:
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>";