This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Dave Marchuk
Posted Jan 18 - Read on Facebook

Apologies for the multitude of questions, but I have to ask one more:

I'm trying to display the current system time within a view that I've created, but I can't figure out how to get the time to display there.

All of the tutorials I've checked out say to use document.write, which puts it in the wrong place, or document.getElementById, but I'm getting "Cannot set property 'innerHTML' of undefined" errors.

I can get the time to display, but not within the element I need it in.

So far I have:

var timeDisplay = new View();

timeDisplay.style = {
"font-size":"12px",
"color":"white",
"z-index":"500",
"border":"2px solid red", // for testing
"text-align":"right"
}

function today(view) {
todayDate = new Date();
document.view.innerHTML = todayDate.getHours(),":",today.getMinutes();
}

today(timeDisplay);

Can anyone give me a hand on how to accomplish this?

5 Comments

Koen Bok

I think you are looking for something like this: http://codepen.io/koenbok/pen/bwepc

Dave Marchuk

Thanks Koen! Love the bonus effect LOL

Dave Marchuk

Hey Koen, I've encountered an issue with the time script: If the time is like 12:09, it's appearing as 12:9, and 12:10 is appearing as 12:1... I've checked online for a fix for this but I'm not having much luck finding one that I can port over... any ideas?

Brett Holcomb

http://stackoverflow.com/questions/3313875/javascript-date-ensure-getminutes-gethours-getseconds-puts-0-in-front-i
view.html =
now.getHours() + ":" +
now.getMinutes() + ":" +
(now.getSeconds() < 10 ? '0'+now.getSeconds(): now.getSeconds());

Dave Marchuk

Thanks Brett! Worked like a charm. The ones I found didn't integrate well, but yours solved the problem!

Read the entire post on Facebook