如何保持while循环添加分钟 [英] How to keep while loop adding minutes

查看:86
本文介绍了如何保持while循环添加分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从用户结束时间在一个开启时间上添加30分钟并显示时间

I am trying to make from the users End time add 30 mintues on an and on an on and display time

function() {

           var toTime = new Date(result2);

           while (true) {

               var toTime30 = new Date(toTime.getTime() + toTime.getTimezoneOffset() *30 * 1000);
               var toTime60 = new Date(toTime30.getTime() + 30 * 60 * 1000);

               var addMin = toTime30 + "" + toTime60;


                   alert(addMin);
                   break;

           }



现在代码只在02:00到02:30之间添加,我怎么能这样做呢是否会增加30分钟的时间?


Right now the code only adds first for ex 02:00 to 02:30 how could i do so it keeps adding 30 minutes to the time?

推荐答案

第一次结束后你的同时结束的问题是因为你有一个休息命令在你的时间。所以你应该删除这行代码。
The problem that your while end after first time is because you have a break command in your while. So you should remove this line of code.


在某些条件下(例如100次迭代或午夜或其他东西)中断,然后它只有在你达到条件时才会中断。 br />


再次,你应该把这个条件放在while而不是while(true)。
Have the break inside some condition (such as 100 iterations or midnight or something) and then it will break only when you get to the condition.

Than again, you should put that condition in the while instead of having while (true).


这篇关于如何保持while循环添加分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆