我在数据库中保存时间的类型是varchar,现在有一个页面读取了数据,连接到详细页面的时候,时间该如何让他正确显示呢。我采用了“            this.lblTime.Text = Convert.ToDateTime(ta.authortime).ToString();”
可是无法正确显示时间

解决方案 »

  1.   

    正确显示时间??
      是时间格式吗??格式模式 说明
    d              月中的某一天。一位数的日期没有前导零。
    dd             月中的某一天。一位数的日期有一个前导零。
    ddd           周中某天的缩写名称,在 AbbreviatedDayNames 中定义。
    dddd         周中某天的完整名称,在 DayNames 中定义。
    M              月份数字。一位数的月份没有前导零。
    MM          月份数字。一位数的月份有一个前导零。
    MMM      月份的缩写名称,在 AbbreviatedMonthNames 中定义。
    MMMM  月份的完整名称,在 MonthNames 中定义。
    DateTime date=DataTime,Now;  
       Response.Write(date.ToString(format, DateTimeFormatInfo.InvariantInfo));  
      

  2.   

    .ToString(yyyyMMdd);  //20100131
    .ToString(yyyy-MM-dd);//2010-01-31
      

  3.   

    .ToString(yyyyMMdd);  //20100131
    .ToString(yyyy-MM-dd);//2010-01-31这种方式无法实现
      

  4.   

    把你的 varchar字段 内容贴出来看看。
      

  5.   

    确保你的字符串传可以转化为DateTime
    2010-01-24 
    Convert.ToDateTime(ta.authortime).ToString("yyyy-MM-dd");
    2010-01-24 16:06:52 
    Convert.ToDateTime(ta.authortime).ToString("yyyy-MM-dd hh:mm:ss");
      

  6.   

    看下这样行不.
    this.lblTime.Text = Convert.ToDateTime(ta.authortime)..ToLongTimeString();
    前提是你只要时间而不是日期..
      

  7.   

    不好意思,上面的代码多了一个. 
    this.lblTime.Text = Convert.ToDateTime(ta.authortime).ToLongTimeString();
      

  8.   

    既然是字符串类型并且格式也正确,直接赋值不就行了this.lblTime.Text = ta.authortime;
      

  9.   

    select authortime=CONVERT(CHAR(10),authortime,126) FROM TABLE 在数据查询时就将其转换成你想要的样式。
      

  10.   

    原因就是你有2种,
    2010-01-24 16:06:52 
    2010-01-24
    而现在你想用Convert.ToDateTime(ta.authortime)转换着2种是不行的,前面一种是没问题,后面一种转换不了的.
    还有种可能是你varchar字段太短,被截了,把你varchar字段内容贴出来看看