一个计算时间间隔的问题,大家来看看呀

billlyh 2005-06-13 11:48:06
TimeSpan usedate=System.DateTime.Now.ToShortDateString()-Convert.ToDateTime(tUseDate.Value).ToShortDateString();
Response.Write(usedate.TotalHours);



tUseDate.Value为Input所输入的时间
提示错误:
c:\inetpub\wwwroot\zwasset\asset\deviceonline.aspx.cs(68): 运算符“-”无法应用于“string”和“string”类型的操作数
...全文
95 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
humin1906 2005-06-13
  • 打赏
  • 举报
回复
错误提示上不是说的很明白,类型不匹配.TimeSpan 怎么会是string类型呢>?
wingnal 2005-06-13
  • 打赏
  • 举报
回复
ToShortDateString的作用就是其转换成string阿
你可以查查这个函数的返回值类型 是string 当然会出错了

TimeSpan usedate=Convert.ToDateTime(System.DateTime.Now.ToShortDateString())-Convert.ToDateTime(Convert.ToDateTime(tUseDate.Value).ToShortDateString());
billlyh 2005-06-13
  • 打赏
  • 举报
回复
再改成下面的,还是出错!!!
TimeSpan usedate=Convert.ToString(System.DateTime.Now.ToShortDateString().Substring(Convert.ToInt32(Convert.ToDateTime(tUseDate.Value).ToShortDateString())));


c:\inetpub\wwwroot\zwasset\asset\deviceonline.aspx.cs(68): 无法将类型“string”隐式转换为“System.TimeSpan”
billlyh 2005-06-13
  • 打赏
  • 举报
回复
改成下面以后,还是提错

TimeSpan usedate=System.DateTime.Now.ToShortDateString().Substring(Convert.ToDateTime(tUseDate.Value).ToShortDateString());


c:\inetpub\wwwroot\zwasset\asset\deviceonline.aspx.cs(68): 与“string.Substring(int)”最匹配的重载方法具有一些无效参数

c:\inetpub\wwwroot\zwasset\asset\deviceonline.aspx.cs(68): 参数“1” : 无法从“string”转换为“int”

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧