Skip to content

Instantly share code, notes, and snippets.

@supern64
Created January 25, 2019 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supern64/b8b29444b58122fbfb01d0d196676ce8 to your computer and use it in GitHub Desktop.
Save supern64/b8b29444b58122fbfb01d0d196676ce8 to your computer and use it in GitHub Desktop.
Simple Clock with Vue.js
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.22/dist/vue.js"></script>
<center>
The current time is:
<div id="clock"><h1>{{ time }}<h1></div>
</center>
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
function formatTime(dateObj) {
return dateObj.getHours().pad() + ":" + dateObj.getMinutes().pad() + ":" + dateObj.getSeconds().pad()
}
const vm = new Vue({
el: "#clock",
data: {
time: formatTime(new Date())
}
})
setInterval(() => {
vm.time = formatTime(new Date())
}, 500)
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.22/vue.min.js"></script>
body {
font-family: "Segoe UI"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment