{"id":185,"date":"2022-12-09T12:10:39","date_gmt":"2022-12-09T12:10:39","guid":{"rendered":"http:\/\/javigomez.org\/?p=185"},"modified":"2025-09-29T20:34:20","modified_gmt":"2025-09-29T20:34:20","slug":"contar-tiempo-en-javascript","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2022\/12\/09\/contar-tiempo-en-javascript\/","title":{"rendered":"Contar tiempo en Javascript"},"content":{"rendered":"\n<p>El siguiente c\u00f3digo te permite contar el tiempo entre  la pulsaci\u00f3n de dos botones. Se utiliza la funci\u00f3n getTime() para fijar el tiempo al pulsar el primer bot\u00f3n y luego al pulsar el segundo.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"http:\/\/javigomez.org\/wp-content\/uploads\/2022\/12\/image-14-5-1.png\" alt=\"\" class=\"wp-image-186\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n\t&lt;meta charset=\"UTF-8\">\n\t&lt;title>HTML Imports&lt;\/title>\n\t&lt;link rel=\"import\" href=\"X.html\" id=\"miimport\">\n&lt;\/head>\n&lt;body>\n\t\n&lt;button onclick=\"start()\">arranca&lt;\/button>\n&lt;button onclick=\"stop()\">parar&lt;\/button>\n&lt;div id=\"resultado\">&lt;\/div>\n\t&lt;script>\n\n\nvar currentDateObj = new Date();\nvar uno;\nvar dos;\n\nfunction start(){\n\tuno = currentDateObj.getTime();\n\tdocument.getElementById(\"resultado\").innerHTML=\"\";\n}\n\nfunction stop(){\n\tcurrentDateObj = new Date();\n \tvar dos = currentDateObj.getTime();\n\t var tiempo= dos-uno;\n\tvar seg=parseInt(tiempo\/1000);\n\tvar mili= tiempo%1000;\n\tvar hor=0;\n\tconsole.log(mili);\n\tmili = parseInt(mili\/10);\n\tconsole.log(mili);\n\tmin=0;\n\tif (seg>60){\n\t\tmin=parseInt(seg\/60);\n\t\tseg=seg%60;\n\t}\n\tif (min>60){\n\t\thor=parseInt(min\/60);\n\t\tmin=min%60;\n\t}\nif (mili&lt;10) mili=\"0\"+mili;\nif (seg&lt;10) seg=\"0\"+seg;\nif (min&lt;10) min=\"0\"+min;\nif (hor&lt;10) hor=\"0\"+hor;\n\n\tvar txt=hor+\":\"+min + \":\"+ seg + \":\" + mili;\n\tdocument.getElementById(\"resultado\").innerHTML=txt;\n}\n\n\n\t&lt;\/script>\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>El siguiente c\u00f3digo te permite contar el tiempo entre la pulsaci\u00f3n de dos botones. Se utiliza la funci\u00f3n getTime() para fijar el tiempo al pulsar &hellip; <\/p>\n","protected":false},"author":1,"featured_media":186,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[175,204],"class_list":["post-185","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-gettime","tag-javascript"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/comments?post=185"}],"version-history":[{"count":1,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/185\/revisions"}],"predecessor-version":[{"id":969,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/185\/revisions\/969"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media\/186"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}