# Adding a clock to your wix website

**URL:** <https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [August 17, 2021, 9:50pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732 "2021-08-17T21:50:58Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![paxaurora6](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paxaurora6/32/26253_2.png) [@paxaurora6](https://forum.wixstudio.com/u/paxaurora6)\
**Post date:** [August 17, 2021, 9:50pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/1 "2021-08-17T21:50:58Z")

</div>

Hi, on a website made on wix, the owner had a coded clock displaying the correct time (with text). How can I do this? Thanks!

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [August 17, 2021, 10:21pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/2 "2021-08-17T22:21:50Z")

</div>

You can use CANVAS inside the HTML-Component (which you can place where ever you want on your page) to generate Clock which ever you want!

And you even can UPGRADE it and connect its values with your page.

Then you would be able to do following things (for example):

- changing STYLE and COLORS of…
- clock-Text
- clock animated circles
- background-color
- font-size
- font-style and so on (many many more)

Here an working example…  
[https://www.media-junkie.com/canvas-clock](https://www.media-junkie.com/canvas-clock)

---

<div class="post-metadata">

**Author:** ![paxaurora6](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paxaurora6/32/26253_2.png) [@paxaurora6](https://forum.wixstudio.com/u/paxaurora6)\
**Post date:** [August 18, 2021, 2:37am UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/3 "2021-08-18T02:37:43Z")

</div>

So we have to come up with the code ourselves?

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [August 18, 2021, 3:32am UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/4 "2021-08-18T03:32:40Z")

</div>

Normaly yes 😅.  
But i will give today a little insight how to generate such clocks when i am back home. Can take a while.✌

---

<div class="post-metadata">

**Author:** ![paxaurora6](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paxaurora6/32/26253_2.png) [@paxaurora6](https://forum.wixstudio.com/u/paxaurora6)\
**Post date:** [August 18, 2021, 3:59am UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/5 "2021-08-18T03:59:51Z")

</div>

Ok

---

<div class="post-metadata">

**Author:** ![volkaertskristof](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/volkaertskristof/32/18158_2.png) [@volkaertskristof](https://forum.wixstudio.com/u/volkaertskristof)\
**Post date:** [August 18, 2021, 6:39am UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/6 "2021-08-18T06:39:04Z")

</div>

Hi Pax,

If you just whant to display it like  
hours:minuts:seconds (08:35:15)  
and you want to show the clock ticking evry second  
Then here is some small code and no canvas needed .

The only thing you should do is add a text element named txtClock.

```javascript
function clock(){
    let newdate = new Date()
    let settime = newdate.getHours() + ":" + newdate.getMinutes() + ":" + newdate.getSeconds()
    $w("#txtClock").text = settime
}

$w.onReady(async function () {
    setInterval(function(){clock()},1000)
    })

```

This won’t be a visual round clock.

Kind regards,  
Kristof.

---

<div class="post-metadata">

**Author:** ![paxaurora6](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paxaurora6/32/26253_2.png) [@paxaurora6](https://forum.wixstudio.com/u/paxaurora6)\
**Post date:** [August 18, 2021, 4:44pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/7 "2021-08-18T16:44:02Z")

</div>

@volkaertskristof Thank you! This is great. We don’t want to be picky, but is there a way to make it regular time (with dual digits (i.e. 10:03 PM) and have it show AM or PM? On the website it shows it in military time. If you can’t do this, that’s OK.

 ![](https://us1.discourse-cdn.com/wix/original/3X/b/5/b5c8ba1c314b8f08cc1e74669abdefb8ae1da050.jpeg)

---

<div class="post-metadata">

**Author:** ![volkaertskristof](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/volkaertskristof/32/18158_2.png) [@volkaertskristof](https://forum.wixstudio.com/u/volkaertskristof)\
**Post date:** [August 18, 2021, 5:28pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/8 "2021-08-18T17:28:12Z")

</div>

Hi Pax,  
Sure its possible tk have dual digits, (tried it only when it only could have dual digits)  
I’ll try to correct it in a bit if i find the time

---

<div class="post-metadata">

**Author:** ![paxaurora6](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paxaurora6/32/26253_2.png) [@paxaurora6](https://forum.wixstudio.com/u/paxaurora6)\
**Post date:** [August 18, 2021, 5:52pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/9 "2021-08-18T17:52:53Z")

</div>

@volkaertskristof No rush!

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [August 18, 2021, 7:59pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/10 "2021-08-18T19:59:27Z")

</div>

@paxaurora6  
Ok, even if it is already resolved, here the promissed CANVAS-CLOCK.  
I found it somewhere in the net and implemented it into HTML-Component…

```javascript
<html>
  <head>
    <title>Clock</title>  
  </head>

  <body style="background-color:rgba(255, 255, 255, 0.1);">
    <canvas id="canvas" width="500" height="200"> </canvas>
    <script>
      var cvs = document.getElementById('canvas');
      var ctx = cvs.getContext('2d');
      ctx.lineWidth = 10;
      ctx.textAlign = 'center';
      ctx.textBaseline = 'middle';
      ctx.font = '30px Trebuchet MS';
      ctx["font-color"]='black'
      ctx.fillStyle = 'black';
      
      var draw = (function () {
          var start = 1.5 * Math.PI; // Start circle from top
          var end = (2 * Math.PI) / 100; 
          
          return function (x, y, p, text, color) {
              p = p || 100; 
              ctx.strokeStyle = color;

              ctx.beginPath();
              ctx.fillText(text, x, y);
              ctx.arc(x, y, 50, start, p * end + start, false);
              ctx.stroke();
          };
      }());

      var clock = function () {
          var date = new Date;
          var h = date.getHours();
          var m = date.getMinutes();
          var s = date.getSeconds();
          // Find percentage
          var hp = 100 / 12 * (h % 12);
          var mp = 100 / 60 * m;
          var sp = 100 / 60 * s;
          // Ensure double digits
          h = h < 10 ? '0' + h : h;
          m = m < 10 ? '0' + m : m;
          s = s < 10 ? '0' + s : s;
          
          ctx.clearRect(0, 0, cvs.width, cvs.height);
          draw(125, 100, hp, h, 'palevioletred');
          draw(250, 100, mp, m, 'limegreen');
          draw(375, 100, sp, s, 'steelblue');

          setTimeout(clock, 500);
      };
      clock();
    </script>
  </body>
</html>

```

[https://www.media-junkie.com/canvas-clock](https://www.media-junkie.com/canvas-clock)

How to use it?

1. Add an → HTML-Component onto your wished page.
2. Navigate to the component’s options, where you will be able to add the shown code above.
3. Save the changes.
4. Publish the site.
5. Enjoy!

And here some stuff for learning… 😁😀

> **[HTML Canvas Reference](https://www.w3schools.com/tags/ref_canvas.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

> **[CanvasRenderingContext2D - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D)**
>
> The CanvasRenderingContext2D interface, part of the Canvas API, provides the 2D rendering context for the drawing surface of a element.
> It is used for drawing shapes, text, images, and other objects.

Yes, it is a little bit more complex then just a normal digital clock, like provided by Kristof, but has more DESIGN-SKILLS 😁 (and ist very customizable) 😉

---

<div class="post-metadata">

**Author:** ![volkaertskristof](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/volkaertskristof/32/18158_2.png) [@volkaertskristof](https://forum.wixstudio.com/u/volkaertskristof)\
**Post date:** [August 19, 2021, 6:08am UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/11 "2021-08-19T06:08:33Z")

</div>

Hi @paxaurora6

Sorry, had no time anymore yesterday.

What you should do is convert it to a 2 digit string,

Add a function like this

```javascript
function pad(value){

	if(value < 10){
		return "0" + value
	} else {
		return value;
	}
}

```

and use it here.

```javascript
let settime = pad(newdate.getHours())+":"+pad(newdate.getMinutes())+":"+pad(newdate.getSeconds() )

```

If you look at the function you can clearly see what it does

it takes your value (hour,minuts,seconds)  
Compares it to 10  
if its lower then 10  
return “0” + value (00,01,02,03,04,05,06,07,08,09)  
else  
return value (no 0 needed here since its already 2 digits).

Now about AM & PM.  
(In belgium we don’t use AM or PM)  
I don’t know if there is a date/time function for it but you can easly make it.  
Make 2 another functions called returnAMPM & returnHours

```javascript
function returnAMPM(hours){
(
	if(hours<12){
		return "AM"
	} else {
		return "PM"
	}
}

```

```javascript
function returnHours(hours){
	if(hours > 12){
		let newHour = hours-12	
		return hours
	} else {
		return hours
	}

}

```

and again change the line to this

```javascript
let settime = pad(returnHours(newdate.getHours()))+":"+pad(newdate.getMinutes())+":"+pad(newdate.getSeconds() + " " + returnAMPM(newdate.getHours()))

```

Hope this helps.

Kind regards,  
Kristof

---

<div class="post-metadata">

**Author:** ![paxaurora6](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paxaurora6/32/26253_2.png) [@paxaurora6](https://forum.wixstudio.com/u/paxaurora6)\
**Post date:** [August 19, 2021, 4:15pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/12 "2021-08-19T16:15:59Z")

</div>

@volkaertskristof@russian-dima Thank you so much! We will be sure to use both of these techniques whenever we can! You two were such great help!

---

<div class="post-metadata">

**Author:** ![tajfrancois007](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tajfrancois007/32/8008_2.png) [@tajfrancois007](https://forum.wixstudio.com/u/tajfrancois007)\
**Post date:** [November 15, 2022, 4:36pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/13 "2022-11-15T16:36:24Z")

</div>

when i copy past the code into the wix html text box, it does not appaear? just the code it self shows, lol i am new to this, any help? want to add a clock with the time and seconds onto my personal site.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [November 16, 2022, 11:30am UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/14 "2022-11-16T11:30:00Z")

</div>

CODE → provided by Kristof is for your site-page  
CODE → provided by me → is for your HTML-Component.

Read the full POST to understand everything clearly.

---

<div class="post-metadata">

**Author:** ![Allison\_Cressey](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@Allison\_Cressey](https://forum.wixstudio.com/u/Allison_Cressey)\
**Post date:** [October 16, 2024, 6:26pm UTC](https://forum.wixstudio.com/t/adding-a-clock-to-your-wix-website/33732/15 "2024-10-16T18:26:34Z")

</div>

Hi i’m looking for something similar but with a **specific timezone**.  
Can anyone help?

I posted a [new topic here](https://forum.wixstudio.com/t/digital-real-time-clock-with-specific-time-zone/63621) for more info.

@CODE-NINJA
