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”类型的操作数

解决方案 »

  1.   

    改成下面以后,还是提错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”
      

  2.   

    再改成下面的,还是出错!!!
    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”
      

  3.   

    ToShortDateString的作用就是其转换成string阿
    你可以查查这个函数的返回值类型  是string  当然会出错了TimeSpan usedate=Convert.ToDateTime(System.DateTime.Now.ToShortDateString())-Convert.ToDateTime(Convert.ToDateTime(tUseDate.Value).ToShortDateString());
      

  4.   

    错误提示上不是说的很明白,类型不匹配.TimeSpan 怎么会是string类型呢>?