A lightweight, real-time date and time widget for Twine games using the SugarCube 2 story format.
Displays a live, updating clock directly within your passage or globally via StoryCaption.
- Live updating every second
- AM/PM format with full date
- Easy to integrate in any Twine passage
- Optional fixed display in the UI (using
StoryCaption)
- Copy the code from
live-clock-sugarcube.html. - Paste it directly into a passage in your Twine project.
- (Optional) Paste it in the StoryCaption to make it appear on all pages.
<span id="live-time"></span><script>var u=()=>{const d=new Date(),h=((d.getHours()%12)||12),m=d.getMinutes().toString().padStart(2,"0"),s=d.getSeconds().toString().padStart(2,"0"),ampm=d.getHours()<12?"AM":"PM",date=d.toDateString();document.getElementById("live-time").textContent=`${date} β’ ${h}:${m}:${s} ${ampm}`};u();setInterval(u,1000);</script>