You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
707 B
26 lines
707 B
import { computed, onMounted, onBeforeUnmount, ref } from 'vue'
|
|
|
|
export const useTime = () => {
|
|
const date = ref(new Date())
|
|
const timer = ref(null)
|
|
|
|
const currentTime = computed(() => {
|
|
return `${date.value.getHours().toString().padStart(2, '0')}:${date.value.getMinutes().toString().padStart(2, '0')}`
|
|
})
|
|
const currentHour = computed(() => date.value.getHours())
|
|
const currentTimeMinute = computed(() => date.value.getMinutes())
|
|
const getDate = () => {
|
|
timer.value = setInterval(() => {
|
|
date.value = new Date()
|
|
}, 60000)
|
|
}
|
|
|
|
onMounted(getDate)
|
|
onBeforeUnmount(() => clearInterval(timer.value))
|
|
|
|
return {
|
|
currentTime,
|
|
currentHour,
|
|
currentTimeMinute
|
|
}
|
|
}
|
|
|