Asp.net中:
javascript怎么由时间格式转换成string格式

解决方案 »

  1.   

    ToString呗..能不能把你想要的说详细点?举个例子也行啊?
      

  2.   

    是这样的,我用VS把.Exl里面的数据读出来,exl里面的一列是时间格式的,转换的时候经常报错,有没有合适的办法让他不报错。
      

  3.   

    晕,你到底是要日期->字符串,还是字符串->时间
    如果日期->字符串就自己ToXXXXString就是了
      

  4.   

    晕倒,从.Exl里读出到js你不转的话怎么会是时间格式?
      

  5.   

    是这样,在exl里面,比如输入:2008-08-08,他就会自动转换成时间格式。我读的话就会出来很成一串格林时间。带GTS之类的。
      

  6.   

    js中将日期类型转换成字符串型格式(转)2008-06-22 12:13<script language="javascript">
    /////////////////////////////////e///////////////////////
    // 取得当前日期,格式yyyy-mm-dd
    ////////////////////////////////////////////////////////
    function GetCurrentDate()
    {
        var Year=0;
        var Month=0;
        var Day=0;
        var CurrentDate = new Date();    return ChangeDateToString(CurrentDate);
    }
    /////////////////////////////////e///////////////////////
    // 取得当前日期,格式yyyy-mm-dd hh:mm
    ////////////////////////////////////////////////////////
    function GetCurrentTime()
    {
        var Year=0;
        var Month=0;
        var Day=0;
        var CurrentDate = new Date();    return ChangeTimeToString(CurrentDate);
    }
    ////////////////////////////////////////////////////////
    // 将日期类型转换成字符串型格式yyyy-MM-dd 
    ////////////////////////////////////////////////////////
    function ChangeDateToString(DateIn)
    {
        var Year=0;
        var Month=0;
        var Day=0;    var CurrentDate="";    //初始化时间
        Year      = DateIn.getYear();
        Month     = DateIn.getMonth()+1;
        Day       = DateIn.getDate();
        CurrentDate = Year + "-";
        if (Month >= 10 )
        {
            CurrentDate = CurrentDate + Month + "-";
        }
        else
        {
            CurrentDate = CurrentDate + "0" + Month + "-";
        }
        if (Day >= 10 )
        {
            CurrentDate = CurrentDate + Day ;
        }
        else
        {
            CurrentDate = CurrentDate + "0" + Day ;
        }
           return CurrentDate;
    }///////////////////////////////////////////////////////
    // 将日期类型转换成字符串型格式yyyy-MM-dd hh:mm
    ////////////////////////////////////////////////////////
    function ChangeTimeToString(DateIn)
    {
        var Year=0;
        var Month=0;
        var Day=0;
        var Hour = 0;
        var Minute = 0;
        var CurrentDate="";    //初始化时间
        Year      = DateIn.getYear();
        Month     = DateIn.getMonth()+1;
        Day       = DateIn.getDate();
        Hour      = DateIn.getHours();
        Minute    = DateIn.getMinutes();
           CurrentDate = Year + "-";
        if (Month >= 10 )
        {
            CurrentDate = CurrentDate + Month + "-";
        }
        else
        {
            CurrentDate = CurrentDate + "0" + Month + "-";
        }
        if (Day >= 10 )
        {
            CurrentDate = CurrentDate + Day ;
        }
        else
        {
            CurrentDate = CurrentDate + "0" + Day ;
        }
        
         if(Hour >=10)
        {
            CurrentDate = CurrentDate + " " + Hour ;
        }
        else
        {
            CurrentDate = CurrentDate + " 0" + Hour ;
        }
        if(Minute >=10)
        {
            CurrentDate = CurrentDate + ":" + Minute ;
        }
        else
        {
            CurrentDate = CurrentDate + ":0" + Minute ;
        }      
        return CurrentDate;
    }
    </script>