# Gettime set default

**URL:** <https://forum.code.org/t/gettime-set-default/16116>\
**Category:** Coding and Debugging Help\
**Tags:** csd-unit-6\
**Created:** [May 8, 2018, 7:38pm UTC](https://forum.code.org/t/gettime-set-default/16116 "2018-05-08T19:38:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbrandon](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@rbrandon](https://forum.code.org/u/rbrandon)\
**Post date:** [May 8, 2018, 7:38pm UTC](https://forum.code.org/t/gettime-set-default/16116/1 "2018-05-08T19:38:43Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/josh/32/868_2.png) [@josh](https://forum.code.org/u/josh)\
**Post date:** [May 10, 2018, 3:20am UTC](https://forum.code.org/t/gettime-set-default/16116/2 "2018-05-10T03:20:33Z")

</div>

The `getTime()` block returns a timestamp that uses the [Unix epoch](https://en.wikipedia.org/wiki/Unix_time) 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):

```javascript
// 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](https://studio.code.org/projects/applab/A5aWmGrj0QnVSomuKW7t0A/edit)

---

<div class="post-metadata">

**Author:** ![jold](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jold/32/5811_2.png) [@jold](https://forum.code.org/u/jold)\
**Post date:** [May 16, 2018, 4:48pm UTC](https://forum.code.org/t/gettime-set-default/16116/3 "2018-05-16T16:48:20Z")

</div>

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.

> **[Check out what I made](https://studio.code.org/projects/applab/Do9gdMIJCvYI7YvIwFAK1tKUr8CfxgBAWCy4TiPKkgg)**
>
> I wrote the code myself with Code.org
