【发布时间】:2019-06-08 10:21:18
【问题描述】:
如你所料,setSeconds();通常会返回并将当前日期的秒数设置为参数内的指定值。但是无论我在 p5.js 网络编辑器中尝试什么,它都绝对没有效果。
我想编写一些代码来计算角度(从水平方向)和移动物体的方向。尝试在我的代码中任何可以想象的地方插入函数,甚至将我的 sn-p 代码与其他代码隔离,以确保没有不需要的外部代码(如其他变量)影响它。
function seconds_Passed()
{
timePassed = new Date()
timePassed.setSeconds(0); //Has no effect even though many js examples show
//this as the way to do it.
secondsPassed = timePassed.getSeconds();
console.log(secondsPassed);
}
没有错误消息。 预期结果是:当我运行代码时,秒数始终从 0 开始,而不是您在桌面时钟上看到的实际实时秒数。
【问题讨论】:
-
抱歉,没听懂您的意思。 setSeconds() 方法设置日期对象的秒数。我测试了它并且它正在工作。你想用这个功能实现什么? @大卫
标签: javascript date p5.js seconds