DEV Community

Cover image for Clocks and Watches in CSS

Clocks and Watches in CSS

Mads Stoumann on February 25, 2025

A couple of years ago, when CSS trigonometry functions became baseline, I wrote an article about them. One of the examples I did, was a CSS-only an...
Collapse
 
crosschainer profile image
crosschainer

sick

Collapse
 
artydev profile image
artydev • Edited

Awesome, thank you ;-)

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
deathcrafter profile image
Shaktijeet Sahoo

Holy CSS!

Collapse
 
stantheman70 profile image
StanTheMan70

Thank you! This is awesome! However, there's a small issue causing the script to work incorrectly with fractional time zones. For example, when the timezone is set to +9.5, the clock displays the time half an hour earlier than it should.
To fix this, simply replace parseInt with** parseFloat** when retrieving the timezone value from the element attribute. This will ensure that fractional offsets are handled correctly.
This error exists even in the CDN.

Collapse
 
madsstoumann profile image
Mads Stoumann • Edited

Ah, didn't think about that — thanks for letting me know!
I've added this method, so it rounds the timezone to nearest quarter of an hour:

#roundTzOffset(offset) {
  return Math.round((parseFloat(offset) || 0) * 4) / 4
};
Enter fullscreen mode Exit fullscreen mode

And since you're called StanTheMan70 — here's Stan The Man and me, 25 years ago ;-)

StanTheMan

Collapse
 
stantheman70 profile image
StanTheMan70

Image description

Collapse
 
plutonium239 profile image
plutonium239

Nice, but you can just name the variable --d without the underscore, neater.

Collapse
 
madsstoumann profile image
Mads Stoumann

That's to indicate the variable should be considerend "private".

Collapse
 
ezpieco profile image
Ezpie

next I want an overly complicated button made using only CSS. Now that's a keeper

Collapse
 
tmnt-12 profile image
Théo Marceau

🕖

Collapse
 
madhurima_rawat profile image
Madhurima Rawat

This looks so good🌟Thanks for sharing!

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
bigol profile image
José Santos Silva

Great work thanks.

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
michael_phillips_356cb1ff profile image
Michael Phillips

So nice!

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
mileswk profile image
MilesWK

Wow! Very interesting! Clocks are hard! Thanks for sharing!

Collapse
 
madsstoumann profile image
Mads Stoumann

Thank you!

Collapse
 
googlieyes8 profile image
GoogliEyes8

Noice, The clock is so smooth, thanks for sharing

Collapse
 
madsstoumann profile image
Mads Stoumann

Thank you!

Collapse
 
zoujia profile image
zoujia

COOL👍MARK❤

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
mahdijazini profile image
Mahdi Jazini

Good Job !

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
samirhembrom profile image
SAMIR HEMBROM

Absolutely amazing

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
muhayminbinmehmood profile image
Muhaymin Bin Mehmood

Great, It seems awesome 🙌

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
keith_murimi profile image
Keith Murimi

This is timeless CSS at it's best

Collapse
 
madsstoumann profile image
Mads Stoumann

Thank you!

Collapse
 
vilce profile image
Ștefan Vîlce

Awesome!!! Excellent!

Collapse
 
madsstoumann profile image
Mads Stoumann

Thank you!!

Collapse
 
stephensamra profile image
Stephen Samra

This is so cool, thanks for sharing.

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
buecui_salos_72b647d8f62f profile image
Buecui Salos

good quilt

Collapse
 
upgrow profile image
UpGrow

Very good!

Collapse
 
madsstoumann profile image
Mads Stoumann

Thanks!

Collapse
 
ykosinets profile image
Yuriy K.

Great article, thanks.
Always knew that trigonometry is cool ))

Collapse
 
madsstoumann profile image
Mads Stoumann

Yeah, it is!