Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the name of boredom... this page should update a timespan in javascript without jquery.</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;body onload="init()"&gt; &lt;script type="text/javascript"&gt; function init() { updateTimespan(); setInterval(updateTimespan, 3000); } function updateTimespan() { var birth = new Date(1987, 3, 20); // april 20th var now = new Date(); var timespan = getTimespan(birth, now); var content = '' + timespan.years + ' years, ' + timespan.months + ' months, ' + timespan.days + ' days, ' + timespan.hours + ' hours, ' + timespan.minutes + ' minutes, ' + timespan.seconds + ' seconds.'; var p = document.getElementById('pTimespan'); p.innerHTML = content; } function getTimespan(start, end) { var seconds = end.getSeconds() - start.getSeconds(); var minutes = end.getMinutes() - start.getMinutes(); var hours = end.getHours() - start.getHours(); var days = end.getDate() - start.getDate(); var months = end.getMonth() - start.getMonth(); var years = end.getFullYear() - start.getFullYear(); if (seconds &lt; 0) { minutes -= 1; seconds += 60; } if (minutes &lt; 0) { hours -= 1; minutes += 60; } if (hours &lt; 0) { days -= 1; hours += 24; } if (days &lt; 0) { months -= 1; var lastMonthNumber = end.getMonth() - 1; if (lastMonthNumber &lt; 0) { lastMonthNumber += 12; } // will never be Feb. var daysInLastMonth = new Date(end.getFullYear(), lastMonthNumber, 0).getDate(); days += daysInLastMonth; } if (months &lt; 0) { years -= 1; months += 12; } return { years: years, months: months, days: days, hours: hours, minutes: minutes, seconds: seconds }; } &lt;/script&gt; &lt;p&gt; Time since my birth&lt;/p&gt; &lt;p id="pTimespan"&gt; Will be updated&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload