【发布时间】:2012-03-31 04:07:54
【问题描述】:
我只是想了解为什么会抛出这个异常。
不能隐式转换类型“System.DateTime?”到“系统。日期时间”。存在显式转换(您是否缺少演员表?)
这就是我想做的事情
story.BroadcastOn 是从数据库获取的日期时间值(例如:23/03/2012 1:56 Pm)。
我正在尝试将时间从 12 小时格式转换为 24 小时格式,这就是我想要做的
DateTime testconverttime = story.BroadcastOn;`//this is where it throws exception
所以我必须像下面那样使用解析来解决我的问题,但这对我来说没有意义
if (!string.IsNullOrEmpty(story.BroadcastOn.ToString()))
{
DateTime localTime = story.BroadcastOn.Value;//Thanks all for the great suggestion.
converttime = localTime.ToString("dd/MMM/yyyy HH:mm ", CultureInfo.CurrentCulture);
}
我已经将我的 12 小时转换为 24 小时,但试图理解异常,请有人给我一个解释。
【问题讨论】:
标签: c#