Display Current Time
# Display Current Time
This article demonstrates how to dynamically display the current time.
<template>
<div class="clock-container">
<div class="clock">
<div class="time-display">
<div class="neon-text">{{ hours }}</div>
<div class="separator">:</div>
<div class="neon-text">{{ minutes }}</div>
<div class="separator">:</div>
<div class="neon-text">{{ seconds }}</div>
</div>
<div class="date-display neon-text-small">{{ currentDate }}</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
hours: '00',
minutes: '00',
seconds: '00',
currentDate: ''
};
},
methods: {
updateTime() {
const now = new Date();
this.hours = String(now.getHours()).padStart(2, '0');
this.minutes = String(now.getMinutes()).padStart(2, '0');
this.seconds = String(now.getSeconds()).padStart(2, '0');
this.currentDate = now.toLocaleDateString('zh-CN', {
year: 'numeric',
month: 'long',
day: 'numeric',
weekday: 'long'
});
}
},
mounted() {
this.updateTime();
setInterval(this.updateTime, 1000);
}
};
</script>
<style scoped>
.clock-container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
background: radial-gradient(circle at center, #1a1a1a, #000000);
perspective: 1000px;
}
.clock {
padding: 2rem 4rem;
border-radius: 20px;
background: rgba(0, 0, 0, 0.8);
box-shadow: 0 0 20px rgba(0, 0, 255, 0.3),
0 0 40px rgba(0, 0, 255, 0.2),
0 0 60px rgba(0, 0, 255, 0.1);
transform-style: preserve-3d;
animation: float 6s ease-in-out infinite;
}
.time-display {
display: flex;
align-items: center;
gap: 0.5rem;
font-family: 'Arial', sans-serif;
font-size: 5rem;
margin-bottom: 1rem;
}
.neon-text {
color: #fff;
text-shadow: 0 0 5px #fff,
0 0 10px #fff,
0 0 20px #0ff,
0 0 30px #0ff,
0 0 40px #0ff;
animation: glow 1s ease-in-out infinite alternate;
}
.neon-text-small {
font-size: 1.5rem;
color: #fff;
text-shadow: 0 0 5px #fff,
0 0 10px #0ff;
text-align: center;
}
.separator {
color: #0ff;
animation: blink 1s infinite;
}
.date-display {
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid rgba(0, 255, 255, 0.2);
}
@keyframes float {
0%, 100% {
transform: translateY(0) rotateX(0);
}
50% {
transform: translateY(-20px) rotateX(5deg);
}
}
@keyframes glow {
from {
text-shadow: 0 0 5px #fff,
0 0 10px #fff,
0 0 20px #0ff,
0 0 30px #0ff;
}
to {
text-shadow: 0 0 10px #fff,
0 0 20px #fff,
0 0 30px #0ff,
0 0 40px #0ff,
0 0 50px #0ff;
}
}
@keyframes blink {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.3;
}
}
/* Responsive design */
@media (max-width: 768px) {
.time-display {
font-size: 3rem;
}
.neon-text-small {
font-size: 1rem;
}
.clock {
padding: 1.5rem 2rem;
}
}
</style>
# Demo Effect
Copy