The user wants me to create a real-time clock with dynamic greeting messages based on the time of day. Let me create a comprehensive solution with:
- HTML structure for the clock and greeting
- CSS for beautiful styling with animations
- JavaScript for:
- Real-time clock functionality
- Dynamic greeting messages based on time of day
- Date display
- Smooth animations
Let me make it visually appealing with:
- A modern design
- Background that changes based on time of day
- Animated elements
- Responsive design
- Multiple time formats (12h/24h toggle)
Time-based greetings:
- Morning (5 AM - 12 PM): Good Morning
- Afternoon (12 PM - 5 PM): Good Afternoon
- Evening (5 PM - 9 PM): Good Evening
- Night (9 PM - 5 AM): Good Night
I'll also add:
- Current date
- Day of week
- Themed icons for each time period
- Smooth transitions between states # Real-Time Clock with Dynamic Greetings
Here's a beautiful, feature-rich clock with time-based greetings and dynamic themes:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Clock with Greetings</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&family=Orbitron:wght@400;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
transition: background 1s ease;
overflow: hidden;
}
/* Time-based background themes */
body.morning {
background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
}
body.afternoon {
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}
body.evening {
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 50%, #f0932b 100%);
}
body.night {
background: linear-gradient(135deg, #0c0c1e 0%, #1a1a3e 50%, #2d2d5a 100%);
}
/* Animated background particles */
.particles {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
overflow: hidden;
z-index: 0;
}
.particle {
position: absolute;
border-radius: 50%;
animation: float 15s infinite;
opacity: 0.6;
}
body.morning .particle,
body.afternoon .particle {
background: rgba(255, 255, 255, 0.3);
}
body.evening .particle {
background: rgba(255, 200, 100, 0.3);
}
body.night .particle {
background: rgba(255, 255, 255, 0.5);
box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
}
@keyframes float {
0%, 100% {
transform: translateY(100vh) rotate(0deg);
opacity: 0;
}
10% {
opacity: 0.6;
}
90% {
opacity: 0.6;
}
100% {
transform: translateY(-100vh) rotate(720deg);
opacity: 0;
}
}
/* Main container */
.clock-container {
position: relative;
z-index: 1;
text-align: center;
padding: 60px 80px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
border-radius: 30px;
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
}
/* Greeting section */
.greeting-section {
margin-bottom: 30px;
}
.greeting-icon {
font-size: 80px;
margin-bottom: 15px;
animation: bounce 2s ease infinite;
}
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
.greeting-text {
font-size: 2.5rem;
font-weight: 600;
color: white;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
margin-bottom: 5px;
}
.greeting-subtitle {
font-size: 1.1rem;
color: rgba(255, 255, 255, 0.8);
font-weight: 300;
}
/* Clock display */
.clock-display {
margin: 30px 0;
}
.time-wrapper {
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
}
.time-segment {
background: rgba(0, 0, 0, 0.2);
padding: 20px 25px;
border-radius: 15px;
min-width: 100px;
}
.time-value {
font-family: 'Orbitron', monospace;
font-size: 4rem;
font-weight: 700;
color: white;
text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
line-height: 1;
}
.time-label {
font-size: 0.75rem;
color: rgba(255, 255, 255, 0.7);
text-transform: uppercase;
letter-spacing: 2px;
margin-top: 5px;
}
.time-separator {
font-size: 4rem;
color: white;
animation: blink 1s infinite;
font-weight: 300;
}
@keyframes blink {
0%, 50% { opacity: 1; }
51%, 100% { opacity: 0.3; }
}
.period {
font-family: 'Orbitron', monospace;
font-size: 1.5rem;
color: white;
background: rgba(255, 255, 255, 0.2);
padding: 10px 15px;
border-radius: 10px;
margin-left: 10px;
align-self: center;
}
/* Seconds progress bar */
.seconds-bar {
width: 100%;
height: 6px;
background: rgba(255, 255, 255, 0.2);
border-radius: 3px;
margin-top: 20px;
overflow: hidden;
}
.seconds-progress {
height: 100%;
background: linear-gradient(90deg, #fff, rgba(255, 255, 255, 0.5));
border-radius: 3px;
transition: width 0.1s linear;
}
/* Date display */
.date-display {
margin-top: 30px;
padding-top: 25px;
border-top: 1px solid rgba(255, 255, 255, 0.2);
}
.date-day {
font-size: 1.3rem;
color: white;
font-weight: 600;
}
.date-full {
font-size: 1rem;
color: rgba(255, 255, 255, 0.8);
margin-top: 5px;
}
/* Controls */
.controls {
margin-top: 25px;
display: flex;
justify-content: center;
gap: 15px;
flex-wrap: wrap;
}
.control-btn {
background: rgba(255, 255, 255, 0.2);
border: none;
color: white;
padding: 12px 25px;
border-radius: 25px;
cursor: pointer;
font-family: 'Poppins', sans-serif;
font-size: 0.9rem;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 8px;
}
.control-btn:hover {
background: rgba(255, 255, 255, 0.3);
transform: translateY(-2px);
}
.control-btn.active {
background: white;
color: #333;
}
/* Quote section */
.quote-section {
margin-top: 25px;
padding: 20px;
background: rgba(0, 0, 0, 0.1);
border-radius: 15px;
max-width: 400px;
margin-left: auto;
margin-right: auto;
}
.quote-text {
font-size: 0.95rem;
color: rgba(255, 255, 255, 0.9);
font-style: italic;
line-height: 1.6;
}
.quote-icon {
font-size: 1.5rem;
margin-bottom: 10px;
}
/* Weather-like info cards */
.info-cards {
display: flex;
justify-content: center;
gap: 20px;
margin-top: 25px;
flex-wrap: wrap;
}
.info-card {
background: rgba(0, 0, 0, 0.15);
padding: 15px 25px;
border-radius: 12px;
text-align: center;
}
.info-card-icon {
font-size: 1.5rem;
margin-bottom: 5px;
}
.info-card-value {
font-size: 1.1rem;
color: white;
font-weight: 600;
}
.info-card-label {
font-size: 0.75rem;
color: rgba(255, 255, 255, 0.7);
text-transform: uppercase;
}
/* Responsive design */
@media (max-width: 768px) {
.clock-container {
padding: 40px 30px;
margin: 20px;
border-radius: 20px;
}
.greeting-icon {
font-size: 60px;
}
.greeting-text {
font-size: 1.8rem;
}
.time-value {
font-size: 2.5rem;
}
.time-segment {
padding: 15px 18px;
min-width: 70px;
}
.time-separator {
font-size: 2.5rem;
}
.period {
font-size: 1rem;
}
.info-cards {
gap: 10px;
}
.info-card {
padding: 12px 18px;
}
}
@media (max-width: 480px) {
.time-wrapper {
flex-wrap: wrap;
}
.time-value {
font-size: 2rem;
}
.time-segment {
min-width: 60px;
padding: 12px 15px;
}
.period {
width: 100%;
margin-left: 0;
margin-top: 10px;
}
}
/* Animation for content */
.fade-in {
animation: fadeIn 0.5s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body class="morning">
<!-- Animated particles -->
<div class="particles" id="particles"></div>
<!-- Main clock container -->
<div class="clock-container fade-in">
<!-- Greeting section -->
<div class="greeting-section">
<div class="greeting-icon" id="greetingIcon">🌅</div>
<div class="greeting-text" id="greetingText">Good Morning</div>
<div class="greeting-subtitle" id="greetingSubtitle">Rise and shine! A new day awaits.</div>
</div>
<!-- Clock display -->
<div class="clock-display">
<div class="time-wrapper">
<div class="time-segment">
<div class="time-value" id="hours">00</div>
<div class="time-label">Hours</div>
</div>
<span class="time-separator">:</span>
<div class="time-segment">
<div class="time-value" id="minutes">00</div>
<div class="time-label">Minutes</div>
</div>
<span class="time-separator">:</span>
<div class="time-segment">
<div class="time-value" id="seconds">00</div>
<div class="time-label">Seconds</div>
</div>
<div class="period" id="period">AM</div>
</div>
<div class="seconds-bar">
<div class="seconds-progress" id="secondsProgress"></div>
</div>
</div>
<!-- Date display -->
<div class="date-display">
<div class="date-day" id="dayName">Monday</div>
<div class="date-full" id="fullDate">January 1, 2024</div>
</div>
<!-- Info cards -->
<div class="info-cards">
<div class="info-card">
<div class="info-card-icon">📅</div>
<div class="info-card-value" id="weekNumber">Week 1</div>
<div class="info-card-label">Week</div>
</div>
<div class="info-card">
<div class="info-card-icon">📆</div>
<div class="info-card-value" id="dayOfYear">Day 1</div>
<div class="info-card-label">of Year</div>
</div>
<div class="info-card">
<div class="info-card-icon">⏰</div>
<div class="info-card-value" id="timezone">UTC+0</div>
<div class="info-card-label">Timezone</div>
</div>
</div>
<!-- Controls -->
<div class="controls">
<button class="control-btn active" id="format12" onclick="setTimeFormat(12)">
🕐 12 Hour
</button>
<button class="control-btn" id="format24" onclick="setTimeFormat(24)">
🕐 24 Hour
</button>
</div>
<!-- Quote section -->
<div class="quote-section">
<div class="quote-icon">💭</div>
<div class="quote-text" id="quoteText">Loading inspirational quote...</div>
</div>
</div>
<script>
// Configuration
let timeFormat = 12;
let currentPeriod = '';
// Greeting configurations
const greetings = {
morning: {
icon: '🌅',
text: 'Good Morning',
subtitle: 'Rise and shine! A new day awaits.',
class: 'morning'
},
afternoon: {
icon: '☀️',
text: 'Good Afternoon',
subtitle: 'Hope your day is going great!',
class: 'afternoon'
},
evening: {
icon: '🌆',
text: 'Good Evening',
subtitle: 'Time to relax and unwind.',
class: 'evening'
},
night: {
icon: '🌙',
text: 'Good Night',
subtitle: 'Sweet dreams await you.',
class: 'night'
}
};
// Inspirational quotes for different times
const quotes = {
morning: [
"Every morning brings new potential, but if you dwell on the misfortunes of the day before, you tend to overlook tremendous opportunities.",
"The way to get started is to quit talking and begin doing. - Walt Disney",
"Today is a new day. Don't let your history interfere with your destiny.",
"Morning is wonderful. Its only drawback is that it comes at such an inconvenient time of day."
],
afternoon: [
"The only way to do great work is to love what you do. - Steve Jobs",
"Believe you can and you're halfway there. - Theodore Roosevelt",
"Success is not final, failure is not fatal: it is the courage to continue that counts.",
"The best time for new beginnings is now."
],
evening: [
"Finish each day and be done with it. You have done what you could.",
"Rest when you're weary. Refresh and renew yourself, your body, your mind, your spirit.",
"The evening's the best part of the day. You've done your day's work.",
"As the sun sets, remember: every ending is just a new beginning in disguise."
],
night: [
"The night is more alive and more richly colored than the day. - Vincent Van Gogh",
"Stars can't shine without darkness.",
"Each night, when I go to sleep, I die. And the next morning, when I wake up, I am reborn. - Gandhi",
"Night is a world lit by itself. - Antonio Porchia"
]
};
// Get time period based on hour
function getTimePeriod(hour) {
if (hour >= 5 && hour < 12) return 'morning';
if (hour >= 12 && hour < 17) return 'afternoon';
if (hour >= 17 && hour < 21) return 'evening';
return 'night';
}
// Update greeting based on time
function updateGreeting(period) {
if (period !== currentPeriod) {
currentPeriod = period;
const greeting = greetings[period];
// Update greeting elements
document.getElementById('greetingIcon').textContent = greeting.icon;
document.getElementById('greetingText').textContent = greeting.text;
document.getElementById('greetingSubtitle').textContent = greeting.subtitle;
// Update body class for theme
document.body.className = greeting.class;
// Update quote
updateQuote(period);
}
}
// Update inspirational quote
function updateQuote(period) {
const periodQuotes = quotes[period];
const randomQuote = periodQuotes[Math.floor(Math.random() * periodQuotes.length)];
document.getElementById('quoteText').textContent = `"${randomQuote}"`;
}
// Pad numbers with leading zeros
function padNumber(num) {
return num.toString().padStart(2, '0');
}
// Get week number
function getWeekNumber(date) {
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
const pastDaysOfYear = (date - firstDayOfYear) / 86400000;
return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7);
}
// Get day of year
function getDayOfYear(date) {
const start = new Date(date.getFullYear(), 0, 0);
const diff = date - start;
const oneDay = 1000 * 60 * 60 * 24;
return Math.floor(diff / oneDay);
}
// Format timezone
function formatTimezone(date) {
const offset = -date.getTimezoneOffset();
const hours = Math.floor(Math.abs(offset) / 60);
const sign = offset >= 0 ? '+' : '-';
return `UTC${sign}${hours}`;
}
// Main clock update function
function updateClock() {
const now = new Date();
let hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
const milliseconds = now.getMilliseconds();
// Get time period and update greeting
const period = getTimePeriod(hours);
updateGreeting(period);
// Format hours based on selected format
let displayHours = hours;
let periodText = '';
if (timeFormat === 12) {
periodText = hours >= 12 ? 'PM' : 'AM';
displayHours = hours % 12 || 12;
document.getElementById('period').style.display = 'block';
} else {
document.getElementById('period').style.display = 'none';
}
// Update time display
document.getElementById('hours').textContent = padNumber(displayHours);
document.getElementById('minutes').textContent = padNumber(minutes);
document.getElementById('seconds').textContent = padNumber(seconds);
document.getElementById('period').textContent = periodText;
// Update seconds progress bar
const progressPercent = ((seconds * 1000 + milliseconds) / 60000) * 100;
document.getElementById('secondsProgress').style.width = `${progressPercent}%`;
// Update date display
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];
document.getElementById('dayName').textContent = days[now.getDay()];
document.getElementById('fullDate').textContent =
`${months[now.getMonth()]} ${now.getDate()}, ${now.getFullYear()}`;
// Update info cards
document.getElementById('weekNumber').textContent = `Week ${getWeekNumber(now)}`;
document.getElementById('dayOfYear').textContent = `Day ${getDayOfYear(now)}`;
document.getElementById('timezone').textContent = formatTimezone(now);
}
// Set time format
function setTimeFormat(format) {
timeFormat = format;
document.getElementById('format12').classList.toggle('active', format === 12);
document.getElementById('format24').classList.toggle('active', format === 24);
updateClock();
}
// Create floating particles
function createParticles() {
const container = document.getElementById('particles');
const particleCount = 30;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
// Random properties
const size = Math.random() * 10 + 5;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
particle.style.left = `${Math.random() * 100}%`;
particle.style.animationDelay = `${Math.random() * 15}s`;
particle.style.animationDuration = `${Math.random() * 10 + 10}s`;
container.appendChild(particle);
}
}
// Initialize
function init() {
createParticles();
updateClock();
// Update clock every 100ms for smooth progress bar
setInterval(updateClock, 100);
// Change quote every 30 seconds
setInterval(() => {
updateQuote(currentPeriod);
}, 30000);
}
// Start the clock
init();
</script>
</body>
</html>
Features
🕐 Real-Time Clock
- Displays hours, minutes, and seconds
- Smooth seconds progress bar
- Toggle between 12-hour and 24-hour format
🌅 Dynamic Greetings
| Time Range | Greeting | Theme |
|---|
| 5 AM - 12 PM | Good Morning | Purple gradient |
| 12 PM - 5 PM | Good Afternoon | Warm orange/yellow |
| 5 PM - 9 PM | Good Evening | Sunset orange/red |
| 9 PM - 5 AM | Good Night | Dark blue/purple |
📅 Date Information
- Full date display
- Day of the week
- Week number
- Day of the year
- Timezone indicator
✨ Visual Features
- Theme changes based on time of day
- Animated floating particles (stars at night)
- Glassmorphism design
- Smooth transitions
- Responsive layout
💭 Inspirational Quotes
- Time-appropriate quotes
- Automatically rotates every 30 seconds
Preview
The clock automatically:
- Detects the current time
- Applies the appropriate theme
- Shows relevant greeting and quote
- Updates in real-time with smooth animations