Sunrise and sunset calculations for api weather machine

So i am doing the api weather machine. I want to display the users sunrise and sunset time. When i call this api, all i get is this number for sunrise: 1507473344. How do i convert this into a time? Is it a location, direction? I switched around two numbers to make sure i wasn’t accidentally posting my location or anything. Please help, thanks :slight_smile:

1 Like

A Unix timestamp?

You can convert it like this:

1 Like

unix_timestamp is not defined

doing this in

Its second from 1970 right?

The number you get is indeed seconds. JS’s new Date() takes in a number of milliseconds. So to get your date:

let unix = 1507473344;
let date = new Date(unix*1000);

console.log(date);   // 2017-10-08T14:35:44.000Z

How how would i get my sunrise and sunset in a readable format? Like for instance, 8:05am to 9:06pm

EDIT: Or easier:

1 Like

Thanks, ill use this.