setTimeout 立即运行函数

setTimeout runs function immediately

我正在尝试在一段时间后使用 'setTimeout' 到 运行 'window.open' 功能。如果我用 parent 的 属性 计算时间差,然后立即使用 'setTimeout' 的输出,'window.open' 函数 运行s。但是,如果我只是给变量 'diffms' 一个数字,它就可以正常工作。 我正在使用 React,我该如何解决这个问题?

// const diffms = 10000;
const diffms = moment(this.props.schedule.time).diff(moment());
  setTimeout(() => {
    window.open("https://www.google.com");
}, diffms);

SetTimeout 有 Maximum Delay Value

包括 Internet Explorer、Chrome、Safari 和 Firefox 在内的浏览器在内部将延迟存储为 32 位有符号整数。

当使用大于 2,147,483,647 毫秒(约 24.8 天)的延迟时,这会导致整数溢出,导致立即执行超时。

请在此处查看更多详细信息:

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#:~:text=Maximum%20delay%20value&text=This%20causes%20an%20integer%20overflow,the%20timeout%20being%20executed%20immediately.