Var new date string

var food = new Date(“Sat Feb 4 15:05:00 2017”);

I need to help to use this line with automatic get today date but clock will be static how can I do it?

What do you mean by “clock will be static”?

BTW, food is a really bad name for a variable that holds a date.


You can use a timer to update it. Have you learned about using timers and intervals?

1 Like

See this code below.It’s a timer that I make in the liveweave that dynamically shows the present time. The HTML code is this:

<!DOCTYPE html>
<script type="text/javascript" src=""></script>
<title>HTML5, CSS3 and JavaScript demo</title>
<!-- Start your code here -->

<div class="lw">Hello Weaver!</div>

<!-- End your code here -->

And the JQuery code is this:

var a=document.createElement('p');

    var hours=new Date().getHours();
    var minutes=new Date().getMinutes();
    var seconds=new Date().getSeconds();

First I create a new paragraph element called a.
Then I append this paragraph into the div with classname= lw.
I use the setinterval function to refresh the HTML content of the paragraph every 1000ms or 1 sec.
As you see I create threevariables to take the hours, minutes and seconds.And finally I set these three variables into a.HTML property.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.