Created
May 2, 2021 18:05
-
-
Save lucaong/595229f9c8e9bd09a27c22e68107db47 to your computer and use it in GitHub Desktop.
Ore Trascorse // source https://jsbin.com/qeripub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Ore Trascorse</title> | |
<style id="jsbin-css"> | |
body { | |
font-family: Helvetica, Arial, sans-serif; | |
font-size: 16px; | |
color: #333; | |
} | |
.container { | |
max-width: 800px; | |
} | |
label { | |
display: block; | |
font-weight: 600; | |
margin-bottom: 1em; | |
} | |
input { | |
display: block; | |
width: 100%; | |
font-size: 16px; | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
padding: 5px; | |
} | |
.text-big { | |
font-weight: 600; | |
font-size: 20px; | |
} | |
#output { | |
font-size: 34px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>Calcolo ore trascorse</h1> | |
<label> | |
Inizio: | |
<input type="datetime-local" name="fromTime" id="fromTime"> | |
</label> | |
<label> | |
Fine: | |
<input type="datetime-local" name="toTime" id="toTime"> | |
</label> | |
<div> | |
<label class="text-big"> | |
Ore trascorse: | |
<input readonly type="text" id="output"> | |
</label> | |
</div> | |
</div> | |
<script id="jsbin-javascript"> | |
const fromTimeInput = document.querySelector('input#fromTime') | |
const toTimeInput = document.querySelector('input#toTime') | |
const output = document.querySelector('#output') | |
let fromTime = null | |
let toTime = null | |
const calculateAndDisplay = (fromTime, toTime) => { | |
const millis = toTime.valueOf() - fromTime.valueOf() | |
const hours = millis / 1000 / 60 / 60 | |
console.log(hours.toFixed(0)) | |
output.value = hours.toFixed(0) + '' | |
} | |
fromTimeInput.addEventListener('change', (event) => { | |
fromTime = new Date(event.target.value) | |
if (fromTime && toTime) { | |
calculateAndDisplay(fromTime, toTime) | |
} | |
}) | |
toTimeInput.addEventListener('change', (event) => { | |
toTime = new Date(event.target.value) | |
if (fromTime && toTime) { | |
calculateAndDisplay(fromTime, toTime) | |
} | |
}) | |
output.addEventListener('click', (event) => { | |
event.target.select() | |
document.execCommand('copy') | |
}) | |
</script> | |
<script id="jsbin-source-css" type="text/css">body { | |
font-family: Helvetica, Arial, sans-serif; | |
font-size: 16px; | |
color: #333; | |
} | |
.container { | |
max-width: 800px; | |
} | |
label { | |
display: block; | |
font-weight: 600; | |
margin-bottom: 1em; | |
} | |
input { | |
display: block; | |
width: 100%; | |
font-size: 16px; | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
padding: 5px; | |
} | |
.text-big { | |
font-weight: 600; | |
font-size: 20px; | |
} | |
#output { | |
font-size: 34px; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const fromTimeInput = document.querySelector('input#fromTime') | |
const toTimeInput = document.querySelector('input#toTime') | |
const output = document.querySelector('#output') | |
let fromTime = null | |
let toTime = null | |
const calculateAndDisplay = (fromTime, toTime) => { | |
const millis = toTime.valueOf() - fromTime.valueOf() | |
const hours = millis / 1000 / 60 / 60 | |
console.log(hours.toFixed(0)) | |
output.value = hours.toFixed(0) + '' | |
} | |
fromTimeInput.addEventListener('change', (event) => { | |
fromTime = new Date(event.target.value) | |
if (fromTime && toTime) { | |
calculateAndDisplay(fromTime, toTime) | |
} | |
}) | |
toTimeInput.addEventListener('change', (event) => { | |
toTime = new Date(event.target.value) | |
if (fromTime && toTime) { | |
calculateAndDisplay(fromTime, toTime) | |
} | |
}) | |
output.addEventListener('click', (event) => { | |
event.target.select() | |
document.execCommand('copy') | |
})</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-family: Helvetica, Arial, sans-serif; | |
font-size: 16px; | |
color: #333; | |
} | |
.container { | |
max-width: 800px; | |
} | |
label { | |
display: block; | |
font-weight: 600; | |
margin-bottom: 1em; | |
} | |
input { | |
display: block; | |
width: 100%; | |
font-size: 16px; | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
padding: 5px; | |
} | |
.text-big { | |
font-weight: 600; | |
font-size: 20px; | |
} | |
#output { | |
font-size: 34px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fromTimeInput = document.querySelector('input#fromTime') | |
const toTimeInput = document.querySelector('input#toTime') | |
const output = document.querySelector('#output') | |
let fromTime = null | |
let toTime = null | |
const calculateAndDisplay = (fromTime, toTime) => { | |
const millis = toTime.valueOf() - fromTime.valueOf() | |
const hours = millis / 1000 / 60 / 60 | |
console.log(hours.toFixed(0)) | |
output.value = hours.toFixed(0) + '' | |
} | |
fromTimeInput.addEventListener('change', (event) => { | |
fromTime = new Date(event.target.value) | |
if (fromTime && toTime) { | |
calculateAndDisplay(fromTime, toTime) | |
} | |
}) | |
toTimeInput.addEventListener('change', (event) => { | |
toTime = new Date(event.target.value) | |
if (fromTime && toTime) { | |
calculateAndDisplay(fromTime, toTime) | |
} | |
}) | |
output.addEventListener('click', (event) => { | |
event.target.select() | |
document.execCommand('copy') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment