Skip to content

Instantly share code, notes, and snippets.

@eligrey
Forked from 140bytes/LICENSE.txt
Last active February 1, 2021 12:00
Show Gist options
  • Save eligrey/985721 to your computer and use it in GitHub Desktop.
Save eligrey/985721 to your computer and use it in GitHub Desktop.
Analog clock of the current time.
function (h /*int hours*/, n /*Date now*/) {
// Clock face characters are U+1F550 to U+1F567, so a surrogate pair must be used
// due to JavaScript being UTF-16
return String.fromCharCode(55357,
56656 + (
(h = (n = new Date).getHours() % 12) ? h - 1 : 11 // offset by hour
) + (n.getMinutes() > 29 && 12) // offset by 12 if past or at 30 mins
);
}
<x id=c><script>setInterval(eval(a="c.innerHTML='&#'+(128336+((h=(n=new Date).getHours(c.style.fontSize=Math.min(innerWidth,innerHeight)+'px')%12)?h-1:11)+(n.getMinutes()>29&&12)),a"),1e3)</script>
function(h,n){return String.fromCharCode(55357,56656+((h=(n=new Date).getHours()%12)?h-1:11)+(n.getMinutes()>29&&12))}

Public domain. No warranty expressed or implied. Use at your own risk. Attribution to Eli Grey is encouraged but optional.

{
"name": "analog-clock"
, "description": "Analog clock of the current time"
, "keywords": ["unicode", "time", "clock"]
}
@jed
Copy link

jed commented May 22, 2011

hmmm, doesn't seem to work for me in FF4 or chrome or safari on OS X... ideas?

@eligrey
Copy link
Author

eligrey commented May 22, 2011

Install a font like Symbola and try again.

@jed
Copy link

jed commented May 22, 2011

hmmm. personally, and this is just me, i think you should find a more reliable way to render it.

@eligrey
Copy link
Author

eligrey commented May 22, 2011

The submission isn't about rendering anything though. It's just about getting the current clock face character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment