Convert UNIX timestamp to hh:mm

I am working on getting JSON data from tvgids.nl, but the start_time and end_time is returned as a UNIX timestamp.

I want to convert this to “hh:mm”, so I need to make this kind of calculation:

So something like this (MS Excel example): UNIX_TIMESTAMP/86400000+DATE(1970,1,1)

How can I do this?

EDIT: I would like to use the time in another flow to turn on my TV and switch to the correct channel.

Your link example based on Excel format functions which are not usable for homey.

I would use homeyscript for example, it is based on javascript. For javascript you can find a lot of convert code examples via google.

1 Like

Maybe this helps? JavaScript Date Formats

1 Like

I am now testing this solution (a HomeyScript with an argument):

image

…which returns the UNIX timestamp in a hh:mm string.

FYI, that will start failing in a few months time when DST becomes active.

1 Like

The 60x60x1e3 is not for DST, but for a “timezone offset”.

Date.toISOString returns a time in UTC, and I need UTC+1.

getTimezoneOffset() returns 0, where I would expect it to return +1 hour.

I used this code in a HomeyScript card in Advanced Flow:

let time = new Date(args[0]*1000).toLocaleString(‘de-DE’,
{
hour12: false,
timeZone: ‘Europe/Berlin’,
hour: “2-digit”,
minute: “2-digit”,
day: “2-digit”,
month: “2-digit”,
year: “numeric”
});
return time;

Adjust the locale (de-DE) and the timezone to yours.
You can adjust the parameters of toLocaleString to get only the hh:mm - or split the result into date and time.

1 Like

Unless DST is in effect and your timezone offset becomes 2 hours.