读xml文档时读出日期格式为:Tue, 10 Apr 2007 05:58:58 GMT
得字符串,请教大家怎么把他转换成"yyyy-MM-dd"
我用
strDate="Tue, 10 Apr 2007 05:58:58 GMT";
strDate=Convert.ToDateTime(strDate).ToString("yyyy-MM-dd");
提示错误:
System.FormatException: 该字符串未被识别为有效的 DateTime。

解决方案 »

  1.   

    http://topic.csdn.net/t/20050410/11/3923816.html
      

  2.   

    TO_DATE('字符串','YYYY-MM-DD HH24:MI:SS')
      

  3.   

    strDate=System.Convert.ToDateTime(strDate).Date.ToString("yyyy-MM-dd");
    这样应该就可以了
      

  4.   

    strDate=System.Convert.ToDateTime(strDate).Date.ToString("yyyy-MM-dd");
    这样也不行啊
    System.FormatException: 该字符串未被识别为有效的 DateTime。
      

  5.   

    我是读得xml中得日期<pubDate>Tue, 10 Apr 2007 03:36:13 GMT</pubDate>
      

  6.   

    呵呵 我说的你不听  那就用我的那种 你用的是ORACLE数据库??
      

  7.   

    我读得是xml文档
    并且是远程得
      

  8.   

    http://rss.sina.com.cn/news/china/focus15.xml
      

  9.   

    那都一样 但你好象还有月份 那你查下TO——DATE的格式 对应上就可以了!!
      

  10.   

    DateTime dt = DateTime.ParseExact("Tue, 10 Apr 2007 05:58:58 GMT", "r", System.Globalization.CultureInfo.CurrentCulture);
                Response.Write(dt.ToString("yyyy-MM-dd"));
      

  11.   

    DateTime dt = DateTime.ParseExact("Tue, 10 Apr 2007 05:58:58 GMT", "r", System.Globalization.CultureInfo.CurrentCulture);
                Response.Write(dt.ToString("yyyy-MM-dd"));
    这个也不行啊
    System.FormatException: 该字符串未被识别为有效的 DateTime。
      

  12.   

    protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //DateTime dt = DateTime.Now;
                //Response.Write(dt.GetDateTimeFormats('r')[0].ToString());            DateTime dt = DateTime.ParseExact("Tue, 10 Apr 2007 05:58:58 GMT", "r", System.Globalization.CultureInfo.CurrentCulture);
                Response.Write(dt.ToString("yyyy-MM-dd"));
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }我测试过了,页面显示2007-04-10
      

  13.   

    Tue, 10 Apr 2007 05:58:58 GMT这个是好用
    但是Tue, 12 Apr 2007 05:58:58 GMT 就不好用了
    我用变量代替就不行
      

  14.   

    但是Tue, 12 Apr 2007 05:58:58 GMT 就不好用了
    -----------------------------------2007年4月12日是星期4,不是星期2,当然转换不了
      

  15.   

    DateTime dt = DateTime.ParseExact("Thu, 12 Apr 2007 05:58:58 GMT", "R", System.Globalization.CultureInfo.CurrentCulture);
                Response.Write(dt.ToString("yyyy-MM-dd"));