Skip to content

Instantly share code, notes, and snippets.

@boldrack
Created April 15, 2022 10:47
Show Gist options
  • Save boldrack/e782c3d9c0fb07bbad698e3b2469077a to your computer and use it in GitHub Desktop.
Save boldrack/e782c3d9c0fb07bbad698e3b2469077a to your computer and use it in GitHub Desktop.
Here take a look
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<style>
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
button {
width: 10rem;
}
.time-container {
display: flex;
flex-flow: column nowrap;
height: 10rem;
}
.timeholder {
display: block;
font-family: 'IBM Plex Sans', sans-serif;
text-align: center;
}
</style>
</head>
<body>
<div class="time-container">
<p class="timeholder"></p>
<button>Toggle</button>
</div>
<script>
const timeholder = document.querySelector('.timeholder')
let hours12 = false
const updateTime = () => {
const newTime = new Intl.DateTimeFormat(
'en-US',
{
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: hours12
}
).format(new Date());
timeholder.innerHTML = newTime;
}
// the timer
setInterval(updateTime, 1000);
// attach the toggle to the button , we do not need to bind cos
// the variable we're changing is also variable. a property of `window`
document.querySelector('button').addEventListener('click', function() {
hours12 = !hours12;
});
</script>
</body>
</html>
@boldrack
Copy link
Author

you should repost the code as a snippet like this <script>const _ = '';</script>

@boldrack
Copy link
Author

Never mind .. pulled it .

@devdesiignn
Copy link

Ok then

@devdesiignn
Copy link

Okay , the main code those exactly what you wanted with a toggle button but not exactly how you wanted it. i'll correct your own code now.

Alright will learn from it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment