我在页面上得到一个日期的字符串,如果不考虑区域语言的情况下可以把它转换成日期,但是考虑到区域语言的时候,我怎么把这个字符串转换成日期,如中文中国的是2009-3-25,英语美国的是3/25/2009,请问怎么转换?在线等,谢谢!!!

解决方案 »

  1.   

    可以参照http://download.microsoft.com/download/1/1/3/11338303-8d34-447d-9151-cfa69ae79683/ACL0260-02.pdf这个是Ajax中实现,看看符合要求吗?
      

  2.   

     DateTime date = Convert.ToDateTime("3/25/2009");
            Response.Write(date.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo));
      

  3.   

    前台: <input type="text" id="txtTime" runat="server" value="2009-3-12" onclick="getT();" />
        <script>
            function getT()
            {
                var s='<%=gDate%>';
                t=new Date(s);
                alert(t);
                
            }
        </script>
    后台:
    using System.Threading;protected DateTime gDate;
    Page_Load()
    {
      Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
      gDate=DateTime.Parse(txtTime.Value);
    }===============
    不晓得上面的解决方法可以不?js转化格式的可以手写转换方式。
    function ExchangeTimeFormat(t)
    {
      var s=document.getElementById('<%=txtTime.ClientID%>').value;
      var t;
      try
      {
        t=new Date(s);   
      }
      catch(e){
        var ary=s.split('-');
        t=new Date(ary[1]+'/'+ary[2]+'/'+ary[0]);
     } return t;
    }