# Convert UNIX timestamp to hh:mm

**URL:** <https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797>\
**Category:** Questions & Help\
**Created:** [December 18, 2022, 2:52pm UTC](https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797 "2022-12-18T14:52:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamster](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hamster/32/16580_2.png) [@Hamster](https://community.homey.app/u/Hamster)\
**Post date:** [December 18, 2022, 2:52pm UTC](https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797/1 "2022-12-18T14:52:33Z")

</div>

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:

> **[How to convert UNIX timestamp to readable date](https://www.plauti.com/support/en_US/35how-tos/how-to-convert-unix-timestamp-to-readable-date)**
>
> The Duplicate Check Job Export feature is available in the Advanced and Premium editions. Duplicate Check Job export shows dates as UNIX Timestamps as it f

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.

---

<div class="post-metadata">

**Author:** ![Joka](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@Joka](https://community.homey.app/u/Joka)\
**Post date:** [December 18, 2022, 3:16pm UTC](https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797/2 "2022-12-18T15:16:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [December 18, 2022, 3:25pm UTC](https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797/3 "2022-12-18T15:25:13Z")

</div>

Maybe this helps? [JavaScript Date Formats](https://www.w3schools.com/js/js_date_formats.asp)

---

<div class="post-metadata">

**Author:** ![Hamster](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hamster/32/16580_2.png) [@Hamster](https://community.homey.app/u/Hamster)\
**Post date:** [December 18, 2022, 4:10pm UTC](https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797/4 "2022-12-18T16:10:17Z")

</div>

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

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/7/077e8617580af28742966bbe7c9cb423b27d2329.png)

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

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 18, 2022, 5:27pm UTC](https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797/5 "2022-12-18T17:27:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hamster](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hamster/32/16580_2.png) [@Hamster](https://community.homey.app/u/Hamster)\
**Post date:** [December 18, 2022, 9:13pm UTC](https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797/6 "2022-12-18T21:13:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [December 18, 2022, 10:33pm UTC](https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797/7 "2022-12-18T22:33:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 19, 2022, 6:44am UTC](https://community.homey.app/t/convert-unix-timestamp-to-hh-mm/73797/8 "2022-12-19T06:44:16Z")

</div>

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