Last active
December 19, 2017 05:04
-
-
Save Dinir/483818112301db6b928aaa897d0e2628 to your computer and use it in GitHub Desktop.
display current time
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> | |
| <style> | |
| body { | |
| margin: 0; | |
| padding: 0; | |
| background-color: black; | |
| color: white; | |
| font-family: "Fira Code"; | |
| font-size: 16px; | |
| } | |
| #display { | |
| display: inline-block; | |
| } | |
| </style> | |
| <body></body> | |
| <script> | |
| const settings = { | |
| 'zeroDigit': '0', | |
| 'separator': ':', | |
| 'updateInterval': 250, | |
| }; | |
| const {zeroDigit, separator, updateInterval} = settings; | |
| const displayDom = document.createElement('div'); | |
| displayDom.setAttribute('id', 'display'); | |
| document.body.appendChild(displayDom); | |
| const currentTime = new Date(); | |
| const timeText = Array(3).fill(zeroDigit.repeat(2)); | |
| const writeTime = () => { | |
| currentTime.setTime(Date.now()); | |
| timeText[0] = (zeroDigit + currentTime.getHours()).substr(-2); | |
| timeText[1] = (zeroDigit + currentTime.getMinutes()).substr(-2); | |
| timeText[2] = (zeroDigit + currentTime.getSeconds()).substr(-2); | |
| displayDom.innerHTML = timeText.join(separator); | |
| }; | |
| writeTime(); | |
| const timeUpdater = setInterval(writeTime, updateInterval); | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment