# Clock update automatically in the Dashboard

**URL:** <https://discourse.nodered.org/t/clock-update-automatically-in-the-dashboard/19781>\
**Category:** Dashboard\
**Created:** [31 December 2019 18:12 UTC](https://discourse.nodered.org/t/clock-update-automatically-in-the-dashboard/19781 "2019-12-31T18:12:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [31 December 2019 18:12 UTC](https://discourse.nodered.org/t/clock-update-automatically-in-the-dashboard/19781/1 "2019-12-31T18:12:52Z")

</div>

Hello,  
I try to display the actual time in the Dashboard but I don't know how can i do.  
It works with a button but i don't know how can I do automatically.  
Thanks in advance for our help.  
My code:

```auto
<script>

function Init(form)
{
  var now=new Date();
  form.Hour.value = now.getHours();
  form.Minute.value = now.getMinutes();
  if (form.Minute.value<10) form.Minute.value = "0"+form.Minute.value;
  form.Second.value = now.getSeconds();
  if (form.Second.value<10) form.Second.value = "0"+form.Second.value;
  form.Day.value = now.getDate();
  form.Month.value = now.getMonth()+1;
  if (form.Month.value<10) form.Month.value = "0"+form.Month.value;
  form.Year.value = now.getYear()+1900;
  

  
}

</script>

<FORM NAME="Clock">
<TABLE WIDTH=100%>

<TR><TD>d.M.Y</TD><TD> <INPUT TYPE="text" NAME="Day" SIZE=2>.
    <INPUT TYPE ="text" NAME="Month" SIZE=2>.<INPUT TYPE="text" NAME="Year" SIZE=4></TD></TR>
    
<TR><TD>h:m:s</TD><TD> 
    <INPUT TYPE ="text" NAME="Hour" SIZE=2>:<INPUT TYPE="text" NAME="Minute" SIZE=2>:<INPUT 
           TYPE="text" NAME="Second" SIZE=2></TD></TR>
           
           
<TR><TD colspan=2 align=center>

<INPUT TYPE="button" VALUE="clock-update" ONCLICK="Init(this.form)">
</TD></TR>

</TABLE>
</FORM>

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 December 2019 21:30 UTC](https://discourse.nodered.org/t/clock-update-automatically-in-the-dashboard/19781/2 "2019-12-31T21:30:19Z")

</div>

The approach I would take would be to use an inject node triggering once a second (or whatever) and generating a timestamp. Then format that in the required way using node-red-contrib-moment (or do it in a function node if you prefer) then send this to appropriate display objects in the dashboard to show it.

---

<div class="post-metadata">

**Author:** ![Randy](https://avatars.discourse-cdn.com/v4/letter/r/2acd7d/32.png) [@Randy](https://discourse.nodered.org/u/Randy)\
**Post date:** [1 January 2020 03:55 UTC](https://discourse.nodered.org/t/clock-update-automatically-in-the-dashboard/19781/3 "2020-01-01T03:55:45Z")

</div>

Not sure if this is what your looking for? It puts a real-time clock in the dashboard title bar.

> [@Time/Date on the Dashboard](https://discourse.nodered.org/t/time-date-on-the-dashboard/2415):
>
> Hi guys, I was wondering if there is an easy way to get the Time & Date on my dashboard so that when I do a screenshot of my temperatures I can tell when it is from. Thanks In Advance Stuart

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [1 January 2020 15:54 UTC](https://discourse.nodered.org/t/clock-update-automatically-in-the-dashboard/19781/4 "2020-01-01T15:54:42Z")

</div>

@Colin, @Randy: Thank you for our inputs.

I would like to use my code like [this](https://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock) because the clock is only a part of my template and so I would not like to use the inject node. But it is a solution.  
I just found [this](https://discourse.nodered.org/t/time-date-on-the-dashboard/2415) post but I would not like to put it on the title bar but in the site like my examplecode. I' m not an expert and so I have problems to change the code.

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [2 January 2020 18:16 UTC](https://discourse.nodered.org/t/clock-update-automatically-in-the-dashboard/19781/5 "2020-01-02T18:16:34Z")

</div>

Hello,  
has nobody an idea? 😟

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [2 January 2020 18:55 UTC](https://discourse.nodered.org/t/clock-update-automatically-in-the-dashboard/19781/6 "2020-01-02T18:55:02Z")

</div>

You've been offered two suggestions so far... but apparently neither meet the brief you want. You may need to either be more patient and hope someone happens to have an exact fit - or roll up your sleeves and start playing around with the code while you wait.

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [2 January 2020 19:34 UTC](https://discourse.nodered.org/t/clock-update-automatically-in-the-dashboard/19781/7 "2020-01-02T19:34:52Z")

</div>

Hello @dceejay,  
thank you for your answer.  
Yes, thats true, I'm verry happy for our help and suggestions.  
I'm a beginner and so I don't understand everything at the begin, sorry.  
I thought it is easier to run the [posted example](https://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock) in node red...  
Now I try to roll up my sleeves and start playing around with the code while I wait.  
Thank you for your understanding and patience.  
Thanks again for our work and helpfulness.
