- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有
let boo = setInterval(() => console.log('boo'), 5000);
假设我想添加另一个间隔函数,但我想确保它不会同时启动:
let bla = setInterval(() => console.log('bla'), 5000);
有没有办法检查第一个 boo
间隔何时触发,并确保 bla
发生,而不是同时发生,但是,比如说,boo
后 2500 毫秒?
最佳答案
but I want to make sure it doesn't fire up at the same time
不能。 JavaScript 在领域(宽松地说,页面/选项卡)内运行单个线程。该线程从开始到结束一次只做一件事。因此,即使这些计时器在同一微秒触发,执行这些回调的作业也会进入同一个队列,并且线程一次处理一个。
如果计时器回调正在完成的工作启动异步进程,则第二个计时器调用可以在计时器回调启动(并返回)之后但异步工作正在完成时进入。如果您想防止这种情况发生,则必须在两者之间进行一些手动同步。
Is there a way to check when is the first boo interval going to fire out and to make sure that bla happens, not at the same time, but, say, 2500 ms after the boo?
我可能会使用单个计时器来做到这一点:
let flag = true;
setInterval(() => {
if (flag) {
console.log("boo");
} else {
console.log("bla");
}
flag = !flag;
}, 2500);
关于javascript - 如何在不同时刻触发不同的 setInterval 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60759952/
我可以访问财务结束日期,并需要根据该日期计算财务开始日期。 这就是我目前的逻辑。 moment('2017-03-31', 'YYYY-MM-DD').quarter() 会给我季度,在本例中为 1。
我想为我的网站构建一个小型日历系统。 当用户创建约会时,他可以在时间段(例如 3 月 3 日到 3 月 7 日)和具体的日期(例如 2016 年 3 月 3 日 11:00)之间进行选择。 我想将其插
我正在编写一个简单的脚本,它将输出特定时间的持续时间。我正在使用 moment 和 moment-duration-format 库 var timeStart = moment('2017-01-2
我在 Moment 中使用 fromNow,似乎得到了一些奇怪的结果。 var moment = require('moment'); var months = { Jan: '1', Feb
有人可以描述我为什么以下返回1 ? moment("2017-12-31").weeks() 但以下返回 52 ? moment("2017-12-30").weeks() 最佳答案 从文档: Bec
var firstDate=moment('Sat Jul 30 2016 00:00:00 GMT+0530 (India Standard Time)'); var secondDate=mome
例如,我有这个日期时间: 01:20:00 06-26-2014 我想减去这样的时间: 00:03:15 之后我想像这样格式化结果: 提前 3 小时 15 分钟。 如何使用 moment.js 做到这
考虑到这一点 http://jsfiddle.net/2a0hsj4z/4/ ,这里作为一个片段: moment.locale("en"); var start = moment("2010-10",
我设置了 3 个日期,开始、结束和今天。 let start_date = '20-06-2018', end_date = '20-06-2018', today = '20-06-2018' 但是
我正在使用 moment 来获取事件的时间,并使用 fromNow 功能 moment(value).fromNow(); 不过,这很有效,它告诉我4 天后。问题是,如果少于一天,则会显示4 小时内。
当我在 us-east-1 托管的 AWS lambda 中运行以下命令时 const currentTime = moment().utc().valueOf(); console.log(new
我正在尝试在我的 laravel 项目中使用 moment.js,而不是使用 vue,但仍然通过 npm 导入包。 我的 app.js 文件: require('moment/moment.js');
我正在寻找一种方法来包含 momentjs使用本地化(在我的例子中是德语),但不使用所有其他本地化(40kb 缩小版本),以保持 slim 。是否可以排除所有其他本地化,但一个特定的本地化? 最佳答案
我正在尝试使用 Moment.js 检测给定日期是否介于两个日期之间。从 2.0.0 版本开始,Tim 添加了 isBefore() 和 isAfter() 用于日期比较。 因为没有 isBetwee
我在 2 个 iso 字符串之间有 6 天的时间: const period = { start: "2020-07-19T22:00:00.000Z", end: "2020-07-25T22:00
我正在使用的后端 API 只能理解 +0000 格式的时区。 我目前得到当前格式的日期: “2017-12-20T16:39:31.000Z” 使用 moment.js 如何以以下字符串格式获取它?
我目前正在编写一个 ASP.NET 应用程序(在 SharePoint 中),该应用程序需要对表单中的字段执行验证。我目前正在寻找验证日期和时间的方法,其中包括比较两个日期时间(小于/大于)和验证格式
今天,我在 Easymock API 中遇到了这组看似有趣的期望设定者'and' 期望 setter :long、short、double、boolean、... 一个例子 public static
有没有办法使用 moment.js 或 moment-timezone 设置时区始终反射(reflect)“美国/纽约”,无论用户从何处访问应用程序? 我已经尝试过此操作,但对象的时区反射(refle
In the moment.js documentation给出了以下示例: moment.duration(1, "minutes").humanize(); // a minute moment.
我是一名优秀的程序员,十分优秀!