42 lines
1.2 KiB
Vue
42 lines
1.2 KiB
Vue
<template>
|
|
<p class="font-bold text-base text-center">{{ time }} {{ date }} </p>
|
|
</template>
|
|
|
|
<script>
|
|
var week = ['AHAD', 'ISNIN', 'SELASA', 'RABU', 'KHAMIS', 'JUMAAT', 'SABTU'];
|
|
|
|
export default {
|
|
data(){
|
|
return{
|
|
time:'',
|
|
date:''
|
|
}
|
|
},
|
|
created(){
|
|
setInterval(this.updateTime, 1000);
|
|
},
|
|
methods: {
|
|
updateTime: function() {
|
|
var cd = new Date();
|
|
|
|
var ampm = cd.getHours() >= 12 ? 'PM' : 'AM';
|
|
|
|
let hours = cd.getHours();
|
|
let minutes = cd.getMinutes();
|
|
hours = hours % 12;
|
|
hours = hours ? hours : 12;
|
|
minutes = minutes < 10 ? '0'+ minutes : minutes;
|
|
|
|
this.time = this.zeroPadding(hours, 2) + ':' + this.zeroPadding(minutes, 2) + ampm;
|
|
this.date = this.zeroPadding(cd.getDate(), 2) + '-' + this.zeroPadding(cd.getMonth()+1, 2) + '-' + this.zeroPadding(cd.getFullYear(), 4) + ' ' + week[cd.getDay()];
|
|
},
|
|
zeroPadding: function(num, digit) {
|
|
var zero = '';
|
|
for(var i = 0; i < digit; i++) {
|
|
zero += '0';
|
|
}
|
|
return (zero + num).slice(-digit);
|
|
}
|
|
}
|
|
}
|
|
</script> |