Вычитание (разница) времени в милисекндах JavaScript

<span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">var</span></code></span> start <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">=</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #000000; font-weight: bold;">new</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><a href="http://www.php.net/date"><span style="color: #990000;">Date</span></a></code></span><span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">;</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #666666; font-style: italic;">// засекли время</span></code></span>
 
<span class="geshifilter"><code class="php geshifilter-php"><span style="color: #666666; font-style: italic;">// что-то сделать</span></code></span>
<span class="geshifilter"><code class="php geshifilter-php"><span style="color: #b1b100;">for</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #009900;">(</span></code></span><span class="geshifilter"><code class="php geshifilter-php"><span style="color: #000000; font-weight: bold;">var</span></code></span> i <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">=</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #cc66cc;">0</span></code></span><span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">;</span></code></span> i <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">&lt;</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #cc66cc;">100000</span></code></span><span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">;</span></code></span> i<span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">++</span></code></span><span class="geshifilter"><code class="php geshifilter-php"><span style="color: #009900;">)</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #009900;">{</span></code></span>
  <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #000000; font-weight: bold;">var</span></code></span> doSomething <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">=</span></code></span> i <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">*</span></code></span> i <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">*</span></code></span> i<span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">;</span></code></span>
<span class="geshifilter"><code class="php geshifilter-php"><span style="color: #009900;">}</span></code></span>
 
<span class="geshifilter"><code class="php geshifilter-php"><span style="color: #000000; font-weight: bold;">var</span></code></span> end <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">=</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #000000; font-weight: bold;">new</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><a href="http://www.php.net/date"><span style="color: #990000;">Date</span></a></code></span><span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">;</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #666666; font-style: italic;">// конец измерения</span></code></span>
 
<span class="geshifilter"><code class="php geshifilter-php">alert</code></span><span class="geshifilter"><code class="php geshifilter-php"><span style="color: #009900;">(</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #0000ff;">"Цикл занял "</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">+</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #009900;">(</span></code></span>end <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">-</span></code></span> start<span class="geshifilter"><code class="php geshifilter-php"><span style="color: #009900;">)</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">+</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #0000ff;">" ms"</span></code></span> <span class="geshifilter"><code class="php geshifilter-php"><span style="color: #009900;">)</span></code></span><span class="geshifilter"><code class="php geshifilter-php"><span style="color: #339933;">;</span></code></span>

<span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">"https://learn.javascript.ru/datetime"</span><span style="color: #339933;">&gt;</span>https<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//learn.javascript.ru/datetime&lt;/a&gt;</span>

Связаться с автором Поддержать автора (что?)
Тэги: 

Комментарии

Если у вас есть вопрос, критика или другое мнение - напишите в комментариях.