我正在尝试转换DateTime?
为,DateTime
但出现此错误:
错误 7 无法隐式转换类型“System.DateTime?” 到“系统。日期时间”。存在显式转换
这是我的代码:
public string ConvertToPersianToShow(DateTime? datetime)
{
DateTime dt;
string date;
dt = datetime;
string year = Convert.ToString(persian_date.GetYear(dt));
string month = Convert.ToString(persian_date.GetMonth(dt));
string day = Convert.ToString(persian_date.GetDayOfMonth(dt));
if (month.Length == 1)
{
month = "0" + Convert.ToString(persian_date.GetMonth(dt));
}
if (day.Length == 1)
{
day = "0" + Convert.ToString(persian_date.GetDayOfMonth(dt));
}
//date = Convert.ToString(persian_date.GetYear(dt)) + "/" +
Convert.ToString(persian_date.GetMonth(dt)) + "/" +
//Convert.ToString(persian_date.GetDayOfMonth(dt));
date = year + "/" + month + "/" + day+"("+dt.Hour+":"+dt.Minute+")";
return date;
}