Gettime set default

A student is trying to on a playground make a sun change time, look like a sun set/sunrise in the beginning of the day and the end of the day then switch to a yellow sun during the daylight hours but the gettime block is making him go back to 1970 and try to figure out the time in milliseconds. He is wondering if he can change the date/time from the default to current.

This is for a door decorating contest and he is going all out with his ideas!

The getTime() block returns a timestamp that uses the Unix epoch as a starting point. Javascript provides a special kind of object called the Date object that allows for pulling useful data out of this timestamp. It can be used like this (note that you’ll need to be in text mode to use the Date object):

// Get a timestamp
var timestamp = getTime();

// convert timestamp to a Date object
var date = new Date(getTime());

// get hours from Date
var hours = date.getHours();

// get minutes from Date
var minutes = date.getMinutes();

// get Seconds from Date
var seconds = date.getSeconds();

Example app

1 Like

I made something that is a bit more complex but will get the sunrise and sunset time from yahoo weather. Thought you may want to take a look at it too.