Why javascript getTime() is not a function?

前端 未结 4 1706
夕颜
夕颜 2020-12-29 18:31

I used the following function,

function datediff()
{
 var dat1 = document.getElementById(\'date1\').value;
 alert(dat1);//i get 2010-04-01
var dat2 = documen         


        
4条回答
  •  生来不讨喜
    2020-12-29 19:10

    dat1 and dat2 are Strings in JavaScript. There is no getTime function on the String prototype. I believe you want the Date.parse() function: http://www.w3schools.com/jsref/jsref_parse.asp

    You would use it like this:

    var date = Date.parse(dat1);
    

提交回复
热议问题