当我从数据库中获取信息时,我无法格式化 Date 类型的信息。
我在用着:
while (sqlReader.Read())
{
var payment = new Payment
{
Id = Convert.ToInt32(sqlReader["Id"]),
Amount = Convert.ToDecimal(sqlReader["Amount"]),
StartDay = Convert.ToDateTime(sqlReader["StartDay"]), //I want this to get this format dd.MM.yyyy
EndDay = Convert.ToDateTime(sqlReader["EndDay"]) //I want this to get this format dd.MM.yyyy
};
Payments.Add(payment);
}
我尝试了我的扩展方法:.ToShortDate()
,尝试过DateTime.ParseExact
,我不断得到这个:String was not recognized as a valid DateTime.