Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在React中获取联机当前时间_Javascript_Reactjs_Time - Fatal编程技术网

Javascript 在React中获取联机当前时间

Javascript 在React中获取联机当前时间,javascript,reactjs,time,Javascript,Reactjs,Time,如果我运行此命令并每秒从服务器获取当前时间,有什么缺点 fetchCurrentTime() { fetch(this.getApiUrl()) .then(resp => resp.json()) .then(resp => { const currentTime = resp.dateString; this.setState({currentTime}) }) } 您可以使用此API获取当前联机

如果我运行此命令并每秒从服务器获取当前时间,有什么缺点

fetchCurrentTime() {
    fetch(this.getApiUrl())
      .then(resp => resp.json())
      .then(resp => {
        const currentTime = resp.dateString;
        this.setState({currentTime})
      })
  } 

您可以使用此API获取当前联机时间

newdate().getTime()