我的后台是SQL SERVER 字段类型是DataTime
我用js写了个得到当前时间的函数,得到的值是正确的,但我要往一个控件赋值,这控件是跟数据库绑定的,值一定要接收DateTime类型才给通过,我如何转换成DateTime类型,再赋值?
this.GetDateTime = function () {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds() + seperator2 + date.getMilliseconds();
    return currentdate;
}

解决方案 »

  1.   

    例子:  var remindTime = "2008-04-02 10:08:44"; //因之前在数据库中的类型为2008-04-02 10:08:44,必须转化为2008/04/02 10:08:44格式才能实例化Date对象      var  str=remindTime.toString();
           str =  str.replace(/-/g,"/");   var oDate1 = new Date(str);   alert(oDate1.getDate());
      

  2.   


    你提问的意思不是将日期的string类型变成date类型么?
      

  3.   

    群里直接给我一个方法就成了
    this.GetDateTime = function () {
    var date = new Date().getVarDate();
    return date;
    }
    控件可以接受~~~
      

  4.   

    只有 Internet Explorer 支持此方法。你测试谷歌或者火狐了吗?
      

  5.   

    sql数据库里面由函数可以变为2008/04/02 10:08:44这个格式,convert(varchar(50),getdate(),111)