Date.getTime()不是Typescript中的函数

时间:2019-11-29 07:49:02

标签: javascript typescript

我在Typescript中有以下代码:

var period = self.getPeriod(someObject.createdTime);

//createdTime is of the type Date


getPeriod(date: Date){
  let today = new Date();
  today.getTime(); // works fine
  date.getTime(); // date.gettime() is not a function

  //rest of the code removed 

}

我在做什么错?如果我尝试在someObject.createdTime.ToUTCString()中传递字符串,则会抛出createdTime.toUTCString()不是函数。

1 个答案:

答案 0 :(得分:0)

var period = self.getPeriod(new Date());

getPeriod(date: Date){
  let today = new Date();
  today.getTime(); 
  date.getTime(); 
}