Like 2:46:44 PM should get me 2:30:00 PM, 3:25:33 AM should get me 3:00:00 AM SO on. I could do
var totalseconds = ((time.getMinutes()* 60) +time.getSeconds());
if(totalseconds>(30*60))
{
time.setMinutes(30);
}
else
{
time.setMinutes(00);
}
time.setSeconds(00);
寻找更好的方法来做到这一点。
最佳答案
//Like 2:46:44 PM should get me 2:30:00 PM, 3:25:33 AM should get me 3:00:00 AM SO on. I could do
var time = new Date();
var mins = time.getMinutes();
var diff = mins % 30;
time.setMinutes(mins - diff);
time.setSeconds(0);
console.log(time);
您可以使用上面提到的代码。
关于javascript - 在 Javascript 中开始半小时的最佳方式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51327467/