cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
seadude
Level 10

Convert Unix Time to Human Readable Time

Hello,

I'm trying to convert Unix Timestamps (example: 1546096196) to Time and DateTime values in PowerApps. I can convert to a Date by dividing the Unix Timestamp by 86400 and adding Date(1970,1,1).

Example:

First(colCurrentWeather.sys).sys.sunrise / 86400 + Date(1970,1,1)

This results in:

image.png

But I want the Time and the DateTime like that shown in this online converter:

image.png

I've tried:

DateTimeValue(
    Text(
        First(colCurrentWeather.sys).sys.sunrise / 86400 + Date(1970,1,1), ShortDateTime))

Does anyone know what I'm missing?

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Convert Unix Time to Human Readable Time

Hi @seadude

An interesting bit of behaviour is that PowerApps is based on JavaScript, and JavaScript works usually with datetimes based on the number of milliseconds from the Unix epoch.

Because of this, we can take the Unix time, multiply by 1,000 (eg convert from seconds to milliseconds), and use the regular PowerApps formatting functions. In your example, the formula would look like this.

Text(1546096196000, "[$-en-US]ddd, dd mmm yyyy hh:mm:ss")

image.png
This saves us from needing to divide by 86400, and adding Date(1970,1,1).

5 REPLIES 5
johnsonjohn
Level: Powered On

Re: Convert Unix Time to Human Readable Time

Hello,

 

Your expression is fine.

If you are using a text field or label, try using a 'datepicker' instead.

Put the default value of date picker to your expression and in the advanced properties of date picker choose DateTimeFormat.LongDateTime as Format

seadude
Level 10

Re: Convert Unix Time to Human Readable Time

Hi @johnsonjohn. Thank you for the idea. It looks like this defaults to 00:00 and not the actual time encoded in the Unix Timestamp.

image.png

I was able to do this with a label as well using the Text() function along with .LongDateTime. But again, it shows as 00:00 rather than the actual time in the Unix Timestamp.

Any other ideas?

Thanks!

Super User
Super User

Re: Convert Unix Time to Human Readable Time

Hi @seadude

An interesting bit of behaviour is that PowerApps is based on JavaScript, and JavaScript works usually with datetimes based on the number of milliseconds from the Unix epoch.

Because of this, we can take the Unix time, multiply by 1,000 (eg convert from seconds to milliseconds), and use the regular PowerApps formatting functions. In your example, the formula would look like this.

Text(1546096196000, "[$-en-US]ddd, dd mmm yyyy hh:mm:ss")

image.png
This saves us from needing to divide by 86400, and adding Date(1970,1,1).

Community Support Team
Community Support Team

Re: Convert Unix Time to Human Readable Time

Hi @seadude,

 

As  an alternative , I  made a test.

21.PNG

 

set Text property of the label to :

Concatenate(Text(DateTimeValue("1970/1/1 1:50:24 "),DateTimeFormat.LongDateTime24),"GMT")

 On your side, you can try to set to :

Concatenate(Text(First(colCurrentWeather.sys).sys.sunrise / 86400 + DateTimeValue("1970/1/1 1:50:24 "),DateTimeFormat.LongDateTime24),"GMT")

Regards,

Eason

Community Support Team _ Eason YU
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
seadude
Level 10

Re: Convert Unix Time to Human Readable Time

Thank you @timl, this was the easiest to implement. I would have never found this on my own! I think I'll suggest it to the Text Function Docs. Might help others too.

 Text(UnixTime * 1000,"[$-en-US]ddd, dd mmm yyyy hh:mm:ss")

 Happy New Year!

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Top Community Contributors for September  2019

Top Community Contributors for September 2019 🎉🎉

Let's thank our top community contributors

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 384 members 5,714 guests
Please welcome our newest community members: